Apex class:
global with sharing class GetAllBetsIntegrationDemo {
private static final String ENDPOINT_BASE = 'https://avenga-school.herokuapp.com/retrieve-data';
private static final String GET_METHOD = 'GET';
private static final String POST_METHOD = 'POST';
@AuraEnabled
public static List<Object> getBets() {
String endpoint = ENDPOINT_BASE;
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(endpoint);
request.setMethod(GET_METHOD);
request.setHeader('Content-Type', 'application/json');
request.setHeader('projectName', 'Totalizator');
HttpResponse response = http.send(request);
List<Object> responseBet = (List<Object>) JSON.deserializeUntyped(response.getBody());
return responseBet;
}
}
JavaScript:
import { LightningElement, wire } from 'lwc';
import getBets from '@salesforce/apex/GetAllBetsIntegrationDemo.getBets';
export default class GetBetsFromExternalApp extends LightningElement {
columns = [
{label: 'Player Name', fieldName: 'playerName', type: 'text'},
{label: 'Amount', fieldName: 'amount', type: 'number'},
{label: 'Win Rate', fieldName: 'winRate', type: 'number'},
{label: 'Lot', fieldName: 'lot', type: 'number'},
{label: 'Status', fieldName: 'status', type: 'text'}
];
@wire(getBets) bets;
}
HTML:
<template>
<lightning-datatable if:true={bets.data}
key-field="id"
data={bets.data}
columns={columns}
hide-checkbox-column=true>
</lightning-datatable>
</template>
JSON return:
{
"amount": 1954,
"winRate": 9,
"lot": 4,
"gameName": "Super Game 1",
"playerName": "John",
"status": "Won"
},
{
"amount": 1954,
"winRate": 4,
"lot": 3,
"gameName": "Super Game 2",
"playerName": "Tom",
"status": "Won"
}
Please help me with this
Best regards Andrii
Hi,
May I also suggest visiting our Developer Community for any coding, apex, visualforce page, trigger, custom button, API or lightning component related questions at developer.salesforce.com/forums. You will get an answer much quicker if you post there. Thank you!
Regards,