How to write external JSON code ServiceNow REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2022 08:38 AM
Hi There
Can anyone please help on how we need to write the below json code into REST Messages in ServiceNow under HTTP Methods-->Variable substitutions. When I run the below code in POSTMAN with the required headers we re getting the success response , but we are not sure how do we test this code in ServiceNow under REST Messages using HTTP Methods.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 09:22 PM
Hi @Hemalatha1 ,
If your issue got resolved close the question by Accepting solution and hit thumb icon then others will get benefited from this.
If not reply and share details.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:45 PM
Hi @Hemalatha1 ,
Do the following steps:
1. In Content paste your JSON as shown in the screenshot.
2. Save the record and then click on the 'Auto-generate Variables' related link.
3. Can see all variables in the 'Variables Substitutions' Related List.
4. If want to use the script in other server side-scripts, click on the 'Preview script usage' related link and can see the script.
If you want to generate JSON entirely through the script, you can use the following script:
var jsonREST = {};
jsonREST.subject = 'test';
jsonREST.expireTime = '2023-9-9 12:12:12';
jsonREST.send = false;
var cat = {};
cat.name = 'snCategory';
jsonREST.category = cat;
var signatoriesArr = [], obj = {}, receiverObj = {};
obj.tenantName = 'TEST';
obj.tenantType = 'XXX';
receiverObj.contact = 'xxxxx@yy.com';
receiverObj.contactType = 'EMAIL';
obj.receiver = receiverObj;
signatoriesArr.push(obj);
jsonREST.signatories = signatoriesArr;
gs.info(JSON.stringify(jsonREST));
Regards,
Reshma
**Please mark my answer correct or helpful based on the impact**
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 10:25 PM
Hi @Hemalatha1 ,
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
If not reply and share details.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2023 02:22 AM
Hi @Hemalatha1 ,
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
If not reply and share status of the issue.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar