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
ArcosArcos 

Attempt to de-reference a null object error is returned when making a POST to the RemedyForce REST API

Hi,
 
I am trying to create an SR using the BMC RemedyForce REST API by making a POST to https://mydomain/services/apexrest/BMCServiceDesk/1.0/ServiceRequest URL. The response is returned with Status=OK and StatusCode=200 which is good, but the response body contains the following JSON:
 
{"Success":false,"Result":null,"ErrorMessage":"Attempt to de-reference a null object","ErrorCode":null}
Interesting, that a POST with the same JSON string using SOAP UI works good.

Below is my code that is calling the REST API:
 
String endPointURL = 'https://mydomain/services/apexrest/BMCServiceDesk/1.0/ServiceRequest';

String authorizationHeader = 'Bearer ' + UserInfo.getSessionId();

Httprequest request = new HttpRequest();
Http http = new Http();

request.setMethod('POST');
request.setEndpoint(endPointURL);
request.setHeader('Accept-Encoding', 'gzip,deflate');
request.setHeader('Content-Type', 'application/json');
request.setHeader('Authorization', authorizationHeader);
request.setCompressed(false);
request.setTimeout(120000);

String jsonString = '{"Fields":[{"Name":"requestDefinitionId","Value":"a3Y24000000L1QcEAK"}],"Answers":[{"QuestionId":"a3U2400000096Q3EAI","Values":["dev"]}]}';

request.setBody(jsonString);

System.debug('Request = ' + request);
System.debug('Request body = ' + request.getBody());

HttpResponse response = http.send(request);

System.debug('responseBody: ' + response.getBody());

What am I doing wrong?
NagendraNagendra (Salesforce Developers) 
Hi Acros,

Please check with below suggestions which might help you to accelerate with above requirement.
  • Go to the org where you are posting and check if these ids are all valid a3Y24000000L1QcEAK, a3U2400000096Q3EAI ?
  • Are you using the same user credentials for both the REST and SOAP callouts ?
  • Did you check the headers that are set in SOAP UI? Are you missing any headers here ?
Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue and becomes a proper solution which results in helping others who are really in need of it.

Best Regards,
Nagendra.P
ArcosArcos
Hi Nagendra,
  1. Yes, both the Ids are valid.
  2. Yes, the credentials are the same.
  3. I am not sure what does it mean missing headers, don't think SOAP UI adds anything special. What else do you think should be there?
Thanks.