Rest API Error "{"error":{"message":"Exception while reading request","detail":"The payload is not "

naveenvenka
Tera Contributor

Trying a outbound integration between two instance .

Goal: If i create an incident in Source , it should create in Target instance as well using Rest message and Business Rule

 

Under Restmessage create a HTTP Post method :

naveenvenka_1-1746218578762.png

Business Rule:

naveenvenka_2-1746218659780.png

 When Im testing the HTTP post method , if i hard coded the values able to create the incident with code 201.

But if im dynamically want to give the values using $Caller_ID , it not creating the incident

 

 

 

 

3 ACCEPTED SOLUTIONS

KevinWhite
Tera Contributor

Use ${variable_name} in the content to substitute variables. Also, instead of wrapping these substitutions in double quotes in the content, use JSON.stringify in the business rule to escape any quotation marks in your input values and to automatically wrap the string in double quotes. If you don't do this, and a user includes a double quotes in their input, your JSON will not be properly formatted and will not parse.

 

The content would look like this:

{
  "caller_id":${caller_id},
  "short_description":${short_description},
  "priority":${Priority},
  "state":${State},
  "urgency":${urgency}
}

 

The section of the business rule script that populates the REST message would look like this:

request.setStringParameterNoEscape('caller_id', JSON.stringify(current.caller_id));
request.setStringParameterNoEscape('short_description', JSON.stringify(current.short_description);
request.setStringParameterNoEscape('Priority', JSON.stringify(current.priority));
request.setStringParameterNoEscape('State', JSON.stringify(current.state));
request.setStringParameterNoEscape('urgency', JSON.stringify(current.urgency));

 

Hope that helps.

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@naveenvenka 

your variable substitutions in Content body field should be like this, so do the same for others

"${caller_id}"

you missed the starting and closing curly brackets

AnkurBawiskar_0-1746343719661.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

_ukasz Rybicki
Giga Guru

Problem Name: Incorrect Variable Substitution in JSON

General Solution:
Use the ${variable} syntax in the JSON body and add the Content-Type header to ensure the payload is parsed correctly by the ServiceNow API.

Detailed Step-by-Step Solution:

  1. Navigate to System Web Services > Outbound > REST Message, open the outbound_demo record, and select the incident_Post HTTP method.

  2. In the HTTP Headers tab, add:

    • Name: Content-Type

    • Value: application/json;charset=UTF-8

  3. In the Content section, paste the following JSON with ${} placeholders:

    {
      "caller_id": "${caller_id}",
      "short_description": "${short_description}",
      "priority": "${priority}",
      "state": "${state}",
      "urgency": "${urgency}"
    }
  4. Verify authentication in the Authentication tab (Basic Auth or OAuth) is configured for the target instance.

  5. Create a Business Rule:

    • Table: Incident [incident]

    • When: After Insert, Asynchronous

    • Advanced

    • Script:

      // After insert -> send to remote instance
      (function executeRule(current) {
        var rm = new sn_ws.RESTMessageV2('outbound_demo','incident_Post');
        var response = rm.execute();
        var code = response.getStatusCode();
        var body = response.getBody();
        if (code !== 201) {
          gs.error('Integration error: ' + code + ' ' + body);
        }
      })(current);
  6. Save and test by creating a new incident, then check logs and verify the incident appears in the target instance.

Alternative:
Use Flow Designer with a REST Action for a no-code integration.

Example Use Case:
Integration Developers can use RESTMessageV2 in an After Insert Business Rule to sync new incidents between instances, leveraging ${variable} placeholders in the JSON body. 😊


Sources:

  1. Rest API Error "{"error":{"message":...}}" – ServiceNow Community (https://www.servicenow.com/community/developer-forum/rest-api-error-quot-quot-error-quot-quot-messag...), explanation of ${variable} syntax requirement.

  2. RESTMessageV2 API reference – ServiceNow Documentation (https://www.servicenow.com/docs/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_refe...), details on execute(), getBody(), and header configuration.

Please mark as the correct answer 😊

View solution in original post

3 REPLIES 3

KevinWhite
Tera Contributor

Use ${variable_name} in the content to substitute variables. Also, instead of wrapping these substitutions in double quotes in the content, use JSON.stringify in the business rule to escape any quotation marks in your input values and to automatically wrap the string in double quotes. If you don't do this, and a user includes a double quotes in their input, your JSON will not be properly formatted and will not parse.

 

The content would look like this:

{
  "caller_id":${caller_id},
  "short_description":${short_description},
  "priority":${Priority},
  "state":${State},
  "urgency":${urgency}
}

 

The section of the business rule script that populates the REST message would look like this:

request.setStringParameterNoEscape('caller_id', JSON.stringify(current.caller_id));
request.setStringParameterNoEscape('short_description', JSON.stringify(current.short_description);
request.setStringParameterNoEscape('Priority', JSON.stringify(current.priority));
request.setStringParameterNoEscape('State', JSON.stringify(current.state));
request.setStringParameterNoEscape('urgency', JSON.stringify(current.urgency));

 

Hope that helps.

Ankur Bawiskar
Tera Patron
Tera Patron

@naveenvenka 

your variable substitutions in Content body field should be like this, so do the same for others

"${caller_id}"

you missed the starting and closing curly brackets

AnkurBawiskar_0-1746343719661.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

_ukasz Rybicki
Giga Guru

Problem Name: Incorrect Variable Substitution in JSON

General Solution:
Use the ${variable} syntax in the JSON body and add the Content-Type header to ensure the payload is parsed correctly by the ServiceNow API.

Detailed Step-by-Step Solution:

  1. Navigate to System Web Services > Outbound > REST Message, open the outbound_demo record, and select the incident_Post HTTP method.

  2. In the HTTP Headers tab, add:

    • Name: Content-Type

    • Value: application/json;charset=UTF-8

  3. In the Content section, paste the following JSON with ${} placeholders:

    {
      "caller_id": "${caller_id}",
      "short_description": "${short_description}",
      "priority": "${priority}",
      "state": "${state}",
      "urgency": "${urgency}"
    }
  4. Verify authentication in the Authentication tab (Basic Auth or OAuth) is configured for the target instance.

  5. Create a Business Rule:

    • Table: Incident [incident]

    • When: After Insert, Asynchronous

    • Advanced

    • Script:

      // After insert -> send to remote instance
      (function executeRule(current) {
        var rm = new sn_ws.RESTMessageV2('outbound_demo','incident_Post');
        var response = rm.execute();
        var code = response.getStatusCode();
        var body = response.getBody();
        if (code !== 201) {
          gs.error('Integration error: ' + code + ' ' + body);
        }
      })(current);
  6. Save and test by creating a new incident, then check logs and verify the incident appears in the target instance.

Alternative:
Use Flow Designer with a REST Action for a no-code integration.

Example Use Case:
Integration Developers can use RESTMessageV2 in an After Insert Business Rule to sync new incidents between instances, leveraging ${variable} placeholders in the JSON body. 😊


Sources:

  1. Rest API Error "{"error":{"message":...}}" – ServiceNow Community (https://www.servicenow.com/community/developer-forum/rest-api-error-quot-quot-error-quot-quot-messag...), explanation of ${variable} syntax requirement.

  2. RESTMessageV2 API reference – ServiceNow Documentation (https://www.servicenow.com/docs/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_refe...), details on execute(), getBody(), and header configuration.

Please mark as the correct answer 😊