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

SuhasPSalunkhe
Kilo Guru

Following things needs to be consider -

1. In rest api script - print request ( what is receiving )

2. In rest api script - try to decompose the request object and based on the structure of request object you have to write code accordingly.

3. Based on your code you will get object properties and their values.

 

Hope this can help you to get the request data.

 

You will find many articles to read JSON formatted data

jaheerhattiwale
Mega Sage
Mega Sage

@Hemalatha1 Follow below steps

 

Update the request body in HTTP methods as follows:

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

 

    "signatories": [
        {
            "tenantName": TEST",
            "tenantType": "XXX",
            "receiver": {
                "contact": "xxxxx@yy.com",
                "contactType": "EMAIL"
            }
        }
    ]
}
 
2. Click on auto generate variables related link
jaheerhattiwale_0-1670996132096.pngjaheerhattiwale_1-1670996139570.png

 

3. Update the Test value field to just snCategory from "name":"snCategory" as in image below:

jaheerhattiwale_2-1670996276539.png

 

4. Click on Test related link

jaheerhattiwale_4-1670996311593.png

 

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

@Hemalatha1 Did you try this? Please try if not already done.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Pavankumar_1
Mega Patron

Hi @Hemalatha1 ,

ServiceNow provided the documentation for this refer below. Let us know if you face any difficulty/doubt.

https://docs.servicenow.com/bundle/tokyo-application-development/page/integrate/outbound-rest/task/t...

https://docs.servicenow.com/en-US/bundle/tokyo-application-development/page/integrate/outbound-rest/...

 

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