Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Request Body is going empty when sending a REST API request outbound

maneesh3
Tera Contributor

Hi Team,

 

I am working on a REST API integration with a third party application and while sending data from ServiceNow, I am unable to send the parameters in Request Body. Client is asking for to send data through Request Body: Following I have approached:

 

maneesh3_0-1761128699522.png

 

 

Below I have given in PUT method:

maneesh3_1-1761128741588.pngmaneesh3_2-1761128795344.png

 

Although Request body is null.

 

Please suggest where I am doing wrong.

 

Thank you!

8 REPLIES 8

@maneesh3 

you can grab the preview script from the REST Message itself

what debugging did you do?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hi Ankur,

 

I have used preview script code in BR and debugging is just I have tested with static sample with 3rd party and static sample testing is working but not dynamic :

 

code used:

 

 try {
    var r = new sn_ws.RESTMessageV2('vCx360', 'Default PUT');

    // Basic fields
    r.setStringParameterNoEscape('comments', current.comments);
    r.setStringParameterNoEscape('number', current.number);
    r.setStringParameterNoEscape('description', current.description);
    r.setStringParameterNoEscape('short_description', current.short_description);
    r.setStringParameterNoEscape('state', current.state);
    r.setStringParameterNoEscape('correlation_id', current.correlation_id);

    // Attachment handling
    var attachmentGR = new GlideRecord('sys_attachment');
    attachmentGR.addQuery('table_sys_id', current.sys_id);
    attachmentGR.addQuery('table_name', current.getTableName());
    attachmentGR.orderByDesc('sys_created_on');
    attachmentGR.setLimit(1); // only latest attachment
    attachmentGR.query();

    if (attachmentGR.next()) {
        var fileName = attachmentGR.file_name + '';
        var fileType = attachmentGR.content_type + '';

        // Get file content in Base64
        var gsa = new GlideSysAttachment();
        var fileContent = gsa.getBytes(attachmentGR);
        var encodedContent = GlideStringUtil.base64Encode(fileContent);

        // Set parameters
        r.setStringParameterNoEscape('file_name', fileName);
        r.setStringParameterNoEscape('file_type', fileType);
        r.setStringParameterNoEscape('file_content', encodedContent);
    } else {
        // No attachment found
        r.setStringParameterNoEscape('file_name', '');
        r.setStringParameterNoEscape('file_type', '');
        r.setStringParameterNoEscape('file_content', '');
    }

    // Execute REST call
    var response = r.execute();
    var responseBody = response.getBody();
    gs.info("Response: " + responseBody);

} catch (ex) {
    gs.error("REST message failed: " + ex.message);
}


})(current, previous);
 
 
 
static sample:
 
{
  "correlation_id": "73",
  "short_description": "Network outage in Bangalore office",
  "description": "Users are unable to connect to VPN and internal applications since 9 AM IST. The issue appears to be network related.",
  "comments": "Initial investigation started. Network team has been notified and working on root cause analysis."
"number": "CSV0028225",
"state": "open",

  "attachments": [
    {
      "file_name": "network_logs.txt",
      "content_type": "text/plain",
      "content": "U2FtcGxlIGxvZ3MgY29udGFpbmluZyBuZXR3b3JrIGVycm9ycyBhbmQgY29ubmVjdGlvbiB0aW1lb3V0cw=="
    }
  ]
}
Static sample test shows 200 code but when running dynamic it is not even triggering
maneesh3_0-1761301013702.png

 

Hi Ankur,

 

Can you please look below my comment

MaxMixali
Giga Guru

Issue: REST API request body is null when sending PUT from ServiceNow

You’re sending a PUT but the request body is empty. This happens when parameters are sent as query params instead of the body, or Content-Type/body template is missing.

-----------------------------------------------------------
A) REST Message + Method (classic)
-----------------------------------------------------------
1. Create REST Message → your endpoint.
2. HTTP Method = PUT.
3. HTTP Headers:
- Content-Type: application/json
4. Request body template:
{
"id": "${id}",
"status": "${status}",
"notes": "${notes}"
}
5. Define variables (id, status, notes).

Script test:
```javascript
var m = new sn_ws.RESTMessageV2('THIRD_PARTY_MSG','put');
m.setStringParameter('id', '12345');
m.setStringParameter('status', 'OPEN');
m.setStringParameter('notes', 'Updated from ServiceNow');
m.setRequestHeader('Content-Type','application/json');
var payload = { id: '12345', status: 'OPEN', notes: 'Updated from ServiceNow' };
m.setRequestBody(JSON.stringify(payload));
var resp = m.execute();
gs.info('HTTP ' + resp.getStatusCode() + ' body=' + resp.getBody());
```

-----------------------------------------------------------
B) Flow Designer → REST Step
-----------------------------------------------------------
1. Add REST Action → Method: PUT.
2. Content type: application/json.
3. Use Request Body mapping, not Request Parameters.
Example JSON:
{
"id": "{{trigger.record.number}}",
"status": "OPEN",
"notes": "Updated by flow {{now}}"
}

-----------------------------------------------------------
C) Fully Scripted Example
-----------------------------------------------------------
```javascript
var r = new sn_ws.RESTMessageV2();
r.setEndpoint('https://api.thirdparty.com/v1/tickets/12345');
r.setHttpMethod('PUT');
r.setRequestHeader('Content-Type','application/json');
var body = { id: '12345', status: 'OPEN', notes: 'Updated from ServiceNow' };
r.setRequestBody(JSON.stringify(body));
var res = r.execute();
gs.info('Status=' + res.getStatusCode() + ' Body=' + res.getBody());
```

-----------------------------------------------------------
Troubleshooting Checklist
-----------------------------------------------------------
- Empty Request body field → must fill it or call setRequestBody().
- Only Parameters mapped → move to Request Body.
- Content-Type must be application/json.
- Verify parameter placeholders resolve properly.
- Outbound HTTP Logs → check sys_http_request/sys_http_response.
- Add gs.info('REQ BODY=' + r.getRequestBody()); to verify.

-----------------------------------------------------------
Minimal Working PUT
-----------------------------------------------------------
```javascript
var m = new sn_ws.RESTMessageV2('MY_MSG','put');
m.setRequestHeader('Content-Type','application/json');
m.setRequestBody('{"ping":"pong"}');
var res = m.execute();
gs.info(res.getStatusCode() + ' ' + res.getBody());
```

If this works, your issue is parameter mapping or Content-Type.