function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chikkuchikku 

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.
User-added image
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);
}
          
 
}
}

 
AbhinavAbhinav (Salesforce Developers) 
Hi Chikku,

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!