+ Start a Discussion
shrayas reddyshrayas reddy 

My task is to get data from api and display it in Table in aura lightning . I am getting the table but data is not inserted in the columns

public class integpost {
      @AuraEnabled
    public static List<string> output(String serviceId, String depositTicker, string withdrawalTicker, integer depositValue ){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.bestrate.org/api/select-service');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        string body = '{"serviceId":"'+serviceId+'","depositTicker" :"' +depositTicker+'" ,"withdrawalTicker":"'+ withdrawalTicker +'","partnerId":null,"depositValue":"'+depositValue+'" }';
             request.setBody(body);
                         
        HttpResponse response = http.send(request);
         string values = response.getBody();
       
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(values);
    
        Map<String, Object> dim = (Map<String, Object>)m.get('result');
        system.debug(dim.get('withdrawalValue'));
       
       List<Object> a = (List<Object>)dim.get('fields');
  
     
        List<string> lsstr= new List<string> ();
       // List<string> lsst= new List<string> ();
        for(Object b:a){
         lsstr.add(String.valueOf(b));
       }
        system.debug(lsstr);
     
  
        return lsstr;

          }
}

output that is returning from method : 
({description=The recipient’s wallet address is the address we send coins bought, once a transaction is finished., name=withdrawalWallet, placeholder=Wallet address, required=true, title=Enter your ETH wallet address}, {defaultValue=user.email, description=Enter your email to start exchange, name=email, placeholder=Email, required=true, title=Enter your email address})no output in aura table


Component:
<aura:component controller="integpost" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="serviceId" type="String" />
    <aura:attribute name="depositTicker" type="String" />
  <aura:attribute name="withdrawalTicker" type="String" />
      <!-- <aura:attribute name="partnerId" type="String" />-->
  <aura:attribute name="depositValue" type="integer" />
    <aura:attribute name="ApiDetail" type="String[]"/>
        <aura:attribute name="Detail" type="List" />
    <lightning:card>
        <lightning:input label="Enter service Id" value="{!v.serviceId}"/><br/>
         <lightning:input label="Enter Deposit ticket" value="{!v.depositTicker}"/><br/>
         <lightning:input label="Enter Withdrawl Ticket" value="{!v.withdrawalTicker}"/><br/>
         <!--<lightning:input label="Enter partnerId" value="{!v.partnerId}"/><br/>-->
         <lightning:input label="Enter deposit Value" value="{!v.depositValue}"/><br/>
         <lightning:button label="getExchange" onclick="{!c.handleApex}" variant="success"/>
     
        <lightning:datatable data="{!v.ApiDetail}"
                         columns="{!v.Detail}"
                         keyField="name"
                         hideCheckboxColumn="false"/>
         

      
        </lightning:card>
</aura:component>

js:

({
    handleApex : function(component, event, helper) {
        var action = component.get('c.output');
        var ion = component.get('v.serviceId');
          var dt = component.get('v.depositTicker');
         var wt = component.get('v.withdrawalTicker');
        // var pid = component.get('v.partnerId');
         var dv = component.get('v.depositValue');
        // var Ad = component.get('v.ApiDetail');
        action.setParams({'serviceId': ion, 'depositTicker':dt, 'withdrawalTicker': wt,
                           'depositValue':dv});
        
         component.set('v.Detail', [
            {label: 'title', fieldName:'title', type: 'text',editable: true},
                {label: 'name', fieldName: 'name', type: 'text'},
                {label: 'placeholder', fieldName: 'placeholder', type: 'text'},
                {label: 'description', fieldName: 'description', type: 'text',editable: true},
                {label: 'required', fieldName: 'required', type: 'boolean',editable: true}
            ]);
        
        action.setCallback(this, function(response){
            var state = response.getState();

            if(state == 'SUCCESS'){
                console.log('apex call is done!', response.getReturnValue()); 
                component.set('v.ApiDetail', response.getReturnValue());
            }
            
        });
        
        $A.enqueueAction(action);
    }
})
Best Answer chosen by shrayas reddy
Maharajan CMaharajan C
Hi Shrayas,

Lightning Datatable need the List<object> in data property  ... But you are returning the List<String> from Apex class.

Just change your apex class like below :
 
public class integpost {
    @AuraEnabled
    public static List<object> output(String serviceId, String depositTicker, string withdrawalTicker, integer depositValue ){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.bestrate.org/api/select-service');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        string body = '{"serviceId":"'+serviceId+'","depositTicker" :"' +depositTicker+'" ,"withdrawalTicker":"'+ withdrawalTicker +'","partnerId":null,"depositValue":"'+depositValue+'" }';
        request.setBody(body);
        
        HttpResponse response = http.send(request);
        string values = response.getBody();
        
        system.debug(' JSON ===> ' + values );
        
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(values);
        
        Map<String, Object> dim = (Map<String, Object>)m.get('result');
        system.debug(dim.get('withdrawalValue'));
        
        List<Object> a = (List<Object>)dim.get('fields');
        
        List<Object> obj = new List<Object>();
        
        for(Object b:a){
            obj.add(b);
        }
        system.debug(' obj ====> ' + obj);
        
        return obj;
        
    }
}

Thanks,
Maharajan.C