Inbound REST, JSON as a field value

Jamsta1912
Tera Guru

Hello all,

I'm working on a system integration with a third party. I have created a web service and transform map in our DEV instance, and we're able to receive and process inbound POSTs with bodies like this:

{
"u_number":"INC7654521",
"u_location":"HQ",
"u_cmdb_ci":"Toaster"
}

However, the third party would like to standardise their outbound messages to have bodies like this:

{
"incident":{
"u_number":"INC7654521",
"u_location":"HQ",
"u_cmdb_ci":"Toaster"
}
}

So, the JSON in my first example itself becomes the value of a field called "incident" in my second example. This doesn't work for the web service I've created, which has field names 'u_number', 'u_location, and 'u_cmdb_ci', and I guess in the second example the message is 'looking for' a field named 'incident'. 

What are my options for processing the inbound message in the second case? I'm thinking I may have to write a script to place each inner field value onto the input row to trigger the transform map, but I would like to know what ya'll think.

Jamie.

1 ACCEPTED SOLUTION

You can construct the response body in the Scripted rest api script as below

 

var body = {};
body.name = "incident";
body.number = "1234";
body.caller = {"id": "user1"};
response.setBody(body);

reference: https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

12 REPLIES 12

SanjivMeher
Kilo Patron
Kilo Patron

You can actually access it using incident.u_number or incident.u_location in JSON.


Please mark this response as correct or helpful if it assisted you with your question.

Jamsta1912
Tera Guru

Hi Sanjivmeher,

Thanks for your reply. Would I need to create a new endpoint and a script to grab the value of each field such as incident.u_location and use those values to create a a new row on the original table?

Jamie.

If you are already using scripted rest API, you just need to change your script.

If you are using table rest api, you will have to create a scripted rest api instead and use that.

 

Can you show me how you have created the REST API now?


Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjivmeher,

I have so far set up a table REST API with a transform map. But my issue is that the third party need to standardise their outbound messages. So I can see that I will need to use a scripted REST API. This will be OK, but I still want to be able to make use of all the logic I've included in my transform map. So my idea is, in the scripted API, grab all the field values and first map them to fields on my original REST table, so that the transform map runs. Does that sound sensible?

Jamie