i am trying to parse a response which is a json object that has JSON array, what I need is to get value in the specific object from the array, inside "results" I'd like to get value from key "id" which is 5438.
this question is similar to mine but it does not really solve my problem
my GET method response is
{
"results": [
{
"url": "https://propertypro.zendesk.com/api/v2/tickets/5438.json",
"id": 5438,
"external_id": null,
"via": {
"channel": "any_channel",
"source": {
"from": {
"service_info": {
"supports_channelback": true,
"supports_clickthrough": false,
"registered_integration_service_name": "WhatsApp",
"registered_integration_service_external_id": "wh"
}
}
}
}
}
]
}
my full code
// Set the GET request parameters
String endpointGet = 'https://propertypro.zendesk.com/api/v2/search.json?'; // be sure this is configured in "Remote Site Settings"
String resourceGetNoReplyWindow = 'query=type%3Aticket+tags%3Asend_whatsapp+status%3Cclosed';
// Set the Methods
String method_get = 'GET';
// Set the credentials
String username = 'some email';
String password = 'Some password';
// define transaction variables for 2 GET requests
HttpRequest reqGetNrw = new HttpRequest();
HttpResponse resGetNrw = new HttpResponse();
Http hGetNrw = new Http();
// Configure the 2 GET requests
reqGetNrw.setEndpoint(endpointGet + resourceGetNoReplyWindow);
reqGetNrw.setMethod(method_get);
// Do the HTTP get request
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
reqGetNrw.setHeader('Authorization', authorizationHeader);
reqGetNrw.setHeader('Content-Type', 'application/json');
resGetNrw = hGetNrw.send(reqGetNrw);
Map<String, Object> deserialized = (Map<String, Object>)JSON.deserializeUntyped(resGetNrw.getBody());
List<Map<String, Object>> data = new List<Map<String, Object>>();
for(Object instance : (List<Object>)deserialized.get('results')){
data.add((Map<String, Object>)instance);
}
System.debug(data);