How to write external JSON code ServiceNow REST API

Hemalatha1
Tera Contributor

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.

 

 

{
    "subject""test",  
    "expireTime""2023-9-9 12:12:12",
    "send"false,
    "category": {
        "name""snCategory"
    },

    "signatories": [
        {
            "tenantName": TEST",
            "tenantType""XXX",
            "receiver": {
                "contact""xxxxx@yy.com",
                "contactType""EMAIL"
            }
        }
    ]
}
8 REPLIES 8

Pavankumar_1
Mega Patron

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.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

reshmapatil
Tera Guru

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.

reshmapatil_0-1671086260664.png

 

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**

 

Pavankumar_1
Mega Patron

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.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Pavankumar_1
Mega Patron

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.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar