+ Start a Discussion
Poorna DeveloperPoorna Developer 

Apex data reader from LWC

Hi ,
I have the following apex api callout code.
Code:
 public class Saltedgelead 
{
    @AuraEnabled(cacheable=true)
    public static string leadtest()
        {
            Http http = new Http();
            HttpRequest request = new HttpRequest();
            request.setEndpoint('https://www.saltedge.com/api/partners/v1/lead_sessions/create?Customer_id=9876541230');
            request.setMethod('POST');
            request.setHeader('Accept','application/json');
            request.setHeader('Content-Type', 'application/json');
            request.setHeader('App-id', 'jbdjhtsfgsdjfbw67uewgruweg6');
            request.setHeader('Secret', 'u7dhsjdf73r8rydhskcnihef73y83');
            request.setBody('{"data": {"customer_id": "9876541230","provider_code": "fake_oauth_client_xf","consent": {"scopes": ["account_details", "transactions_details"]}}}');
            HttpResponse responseg = http.send(request);  
            System.debug(responseg.getBody());
            return responseg.toString();
        } 
}

The above apex code returns a url.
Now I wish to display the return data (Url) in to lwc .
Js:
import { LightningElement, wire, track} from 'lwc';
import getURL from '@salesforce/apex/Saltedgelead.leadtest';
export default class RedirecctedURL extends LightningElement {
    @track lapp;
    @track data;
    @track error;
    @wire (getURL)
    getURL({error,data})
 {
    if (data !== 'undefined') 
    {
        this.lapp = data;
        console.log('Data',data);
    } else if (error) 
    {
        console.log(error);
        this.error = error;
    }
 }
}
html:
<template>
    <lightning-card title="Redirected URL" icon-name="lightning-icon" >
        <div class="slds-m-around_medium">
            <template if:true={lapp}>
                <ul>
               <template for:each={lapp} for:item="app">
                   <li key={app.Id}> {app.Name} </li>
               </template>
            </ul>
           </template>
           <template if:true={error}>
               {error}
           </template>  
        </div>
 </lightning-card>
</template>

But,I get the error like 'Data' is Undefined.
Any idea?
Thanks.
AnudeepAnudeep (Salesforce Developers) 
Can you please comment out the line  console.log('Data',data); and check if you still see the same issue