Request Body is going empty when sending a REST API request outbound
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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:
Below I have given in PUT method:
Although Request body is null.
Please suggest where I am doing wrong.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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:
"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",
"attachments": [
{
"file_name": "network_logs.txt",
"content_type": "text/plain",
"content": "U2FtcGxlIGxvZ3MgY29udGFpbmluZyBuZXR3b3JrIGVycm9ycyBhbmQgY29ubmVjdGlvbiB0aW1lb3V0cw=="
}
]
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Ankur,
Can you please look below my comment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
✅ 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.
