You need to sign in to do that
Don't have an account?
Eric Blaxton 11
Apex Json return error
Hi and thanks in advance for any help provided.
This is my second HTTP call. The call works, but I am confused on the stucture of the JSON. I can successfully work with the "childWorkOrders", but I need to access the "workOrder", which is the Parent. How would I do that?
JSON return:
APEX snippet:
Regards,
Eric
This is my second HTTP call. The call works, but I am confused on the stucture of the JSON. I can successfully work with the "childWorkOrders", but I need to access the "workOrder", which is the Parent. How would I do that?
JSON return:
{ "status": "New", "shortDescription": "xxx", "description": "* 11/11/2020 13:12:53 CST (SVCPOXPO) * xxx", "openedOn": "2020-11-11T13:12:53", "closeOn": "0002-11-30T00:00:00", "workOrder": { "parentWorkOrder": null, "assignedTo": "xxx", "openedOn": "2020-11-11T13:12:53", "lastUpdatedOn": "2020-11-11T13:44:20", "closeOn": "0002-11-30T00:00:00", "shortDescription": "xxx", "description": "xxx", "status": "Assigned", "workOrderNumber": "000007018372", "vendorName": null, "chargeBack": "0.00 ", "invoice": null }, "childWorkOrders": [ { "parentWorkOrder": "000007018372", "assignedTo": "xxx", "openedOn": "2020-11-11T15:18:59", "lastUpdatedOn": "2020-11-11T15:19:01", "closeOn": "0002-11-30T00:00:00", "shortDescription": "Dispenser", "description": null, "status": "Assigned", "workOrderNumber": "000007018381", "vendorName": null, "chargeBack": "0.00 ", "invoice": null } ] }
APEX snippet:
HTTP h2 = new HTTP(); HTTPRequest req2 = new HTTPRequest(); // This gets the work orders. The trick is to get the Maintenance Ticket ID into the (). It would have to be a loop or something req2.setEndpoint(qaEndpoint + '(78401)/GetWorkOrders'); req2.setTimeout(120000); req2.setMethod('GET'); // QA Authorization req2.setHeader('Authorization', 'Bearer ' + tokenkey); HTTPResponse res2 = h2.send(req2); String strResponse2 = res2.getBody(); if(res2.getstatusCode() == 200 && res2.getbody() != null) system.debug('Response: ' + res2.getBody()); { Map<String,Object> newMap2 = (Map<String, Object>)JSON.deserializeUntyped(strResponse2); //strResponse gets top level and lower level details List<Object > valuelist2 = (List<Object>) newMap2.get('workOrder'); system.debug('valuelist2: ' + valuelist2); //Pass values to create/upsert cases (public class createMaintCase) //createMaintCase.upsertCases(valuelist); return null; } // end 2nd HTTPRequestError: From line:
List<Object > valuelist2 = (List<Object>) newMap2.get('workOrder'); System.TypeException: Invalid conversion from runtime type Map<String,ANY> to List<String>
Regards,
Eric
This is based on the sample given in the documentation
Let me know if it helps. If it does, please mark this answer as Best. It may help others in the community. Thank You!