Outbound REST API help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 03:34 AM - edited 04-30-2025 04:08 AM
Hi,
I have been following the this article which has been really useful to create a REST Message: use-bearer-token-for-rest-message-authentication
The first REST Message is working and I am getting the token in the log message however the second REST Message is returning a 400 status code "Bad Request" response.
When I've tested the Rest Message with test values as the variable substitutes it's working fine and I'm getting a 200 status code with the expected response so I assume there is an issue with the script include.
I've checked that companyName, account, sortcode, type and token are all returning the correct values in a log message.
I've attached my script include code & REST Message and this is my script include code:
Can anyone give me any pointers?
Thanks,
Clare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 05:52 AM
Thanks for your help.
I've solved by setting the Request Header and Body in the script include instead of in the REST Message using setStringParameter:
request.setRequestHeader('Authorization','Bearer ' + token);
//Create payload (JSON with key-value pair)
var myObj = {
"customerName": companyName,
"bankAccount": account,
"sortCode": sortcode,
"accountType": type
} ;
//Convert the object to string and set it to Request Body-
request.setRequestBody(JSON.stringify(myObj));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 07:10 AM
Glad to know.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 07:19 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 04:35 AM
@ClareM Recent servicenow versions allowing massl/mutual authentication+oauth setup, you can create application registry,check the mutual authentication checkbox and choose the right profile..If you have all these setup, then no need to pass the token through script. Below reference configuration setup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 04:57 AM
Hi Akiladevi,
I did have a look at the OAuth authentication however it appeared complicated to set up and I wasn't sure how it would work with the bearer token