You need to sign in to do that
Don't have an account?
chikku
How to store particular API response data in variable in apex
I have got a response from API I need to store particular data into a variable and to use.
I need to store token values in a variable with is JSON.
I need to store token values in a variable with is JSON.
public class QueueAbacusAPI { private static String accessToken; @InvocableMethod(label='Abacus' description='Getting customer info from Abacus' ) public static void abacuStagingsapi( ) { abacuStagingsapiFuture1( ); } public static void abacuStagingsapiFuture1( ) { string body= '{'+ ' "username": "administrator ",'+ ' "password": "whatever",'+ ' "deviceId": "a12bc"'+ '}'; Http http = new Http(); HttpRequest request = new HttpRequest(); HttpResponse res = new HttpResponse(); request.setEndpoint(endpointurl);// update endpoint url request.setMethod('POST'); request.setHeader('Accept','application/json'); request.setHeader('Content-Type', 'application/json; charset=utf-8'); request.setBody(body); HttpResponse response= http.send(request); // Parse the JSON response try { res = http.send(request); if (res.getStatusCode() == 200) { System.debug('Success!'); } else { System.debug('HTTP : ' + res.getStatusCode()); } System.debug(res.getBody()); } catch(System.CalloutException e) { System.debug('Callout error: '+ e); } } }
Please check below link for reading json from response and store it in a string variable
https://stackoverflow.com/questions/62261252/apex-salesforce-read-json-from-response-and-store-it-in-a-string-variable
Thanks!