- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 09:54 AM
Hi ServiceNow Community Developers,
I have a REST API that is working fine when testing it in the HTTP Method inside REST Message. Basically I defined a REST API as shown in the REST Message API Definition screenshot and I defined the issueKey and issueBody variables. To test it I just click the Test link inside the HTTP Method and it successfully updates the issue in Jira as expected and it returns a 204 code as shown in the REST API Result screenshot. Now the problem is when I used the Preview Script Usage link and I take the same code that runs successfully on the HTTP Method inside REST Message and copy it into a business rule as shown in the Business rule calling REST API screenshot so that I can now call it dynamically and provide the variables from an incident record, it fails on a 400 error code.
Would you guys please take a look at my code and see what it is that I am doing wrong. It will also be nice to see the payload that I am pushing so that I know that the variables are getting substituted properly but I don't know how to display that. If you guys know please advise as that will also be very helpful in debugging this.
Thanks,
Johannes
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 07:04 PM
Hi ServiceNow Community Developers
I actually figured this out. It looks like you need to put your payload in the Content field inside the REST Message API Definition with the substitution variables defined as shown in the Content field screenshot. Then in your business you dynamically populate the substitution variables as shown the Dynamic population screenshot.
I thought I will share that.
Thanks,
Johannes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 06:12 PM - edited 01-19-2024 06:13 PM
Hi @Johannes Mweli ,
Please check the configured authentication with REST API , when you are testing from REST API page it has the authentication but from BR it's not then add it.
r.setBasicAuth("userName", "Password"); // update the userName and Password values
HTTP 400 ->A 400 Bad Request Error occurs when a request sent to the website server is incorrect or corrupt, and the server receiving the request can't understand it.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 07:04 PM
Hi ServiceNow Community Developers
I actually figured this out. It looks like you need to put your payload in the Content field inside the REST Message API Definition with the substitution variables defined as shown in the Content field screenshot. Then in your business you dynamically populate the substitution variables as shown the Dynamic population screenshot.
I thought I will share that.
Thanks,
Johannes