From Salesforce I am trying to make restful api call to a CPQ system.
- I am able to make a login (POST request)
- I am able to query the Account object & retrieve the id & fields on the Account object in the external system through (GET request)
- Now I need to update the Account record with a value from Salesforce
Example: I have written the JSON Generator code to update Account name on the external system using the Id of the Account retrieved.
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
JSONGenerator gen = JSON.createGenerator(true);
gen.writeStartArray();
gen.writeStartObject();
gen.writeStringField('Id', '0ca0000f8pxds72r');
gen.writeStringField('Name', 'TEST12345');
gen.writeEndObject();
gen.writeEndArray();
String jsonOrders1 = gen.getAsString();
System.debug('jsonOrders: ' + jsonOrders1 );
req.setMethod('POST');
req.setEndpoint('https://cpq.com/rs/8/cpq');
req.setHeader('Content-Type', 'application/json');
req.setBody(jsonOrders1);
req.setCompressed(true);
res = http.send(req);
Status code = 400; Message: content was not a valid JSON object
I tested the same Post request using the Postman plugin in Chrome and it successfully updated the Account on the external system. Below is the JSON Body which I used in the Postman; when I print my json request in Salesforce, I am getting the similar JSON response. Can anyone help in trouble shooting this issue. What am I doing wrong in creating the JSON request.
**JSON used in Postman:**
[
{"Id":"0ca0000f8pxds72r","Name":"TEST123"}
]
**JSON when I print in debug logs in Salesforce**:
[ { "Id" : "0ca0000f8pxds72r", "Name" : "TEST12345"} ]
I was referring their API Documentation. Look under the CPQ OnDemand Web Services API Calls (RESTful) header (Create/Update object)