- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 11:34 AM
Hello,
I have been asked to integrate with a 3rd party, by allowing them to insert records in one of our tables.
The support team at this 3rd party is sending me a JSON payload, but I'm at a loss as to how to parse it into one of our tables. I've been pouring over the servicenow documentation, but all I can find is information about how to structure JSON leaving ServiceNow, not how to parse incoming JSON.
Can someone point me in the right direction?
Here is the entirety of the payload I'm getting:
{
"action": "created",
"event": "request",
"request": {
"brokerage_name": "My Fake Institution",
"brokerage_url": "www.fakeinstitution.com",
"requested": "2017-04-03T17:11:23.527",
"user": 1572940
},
"user": {
"email": "fakemail@example.com",
"id": 1572940,
"name": "Fake User",
"phone": null,
"username": null,
"value": null
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 01:48 PM
Hi Miles,
As Shahid, if you can have control on what the third party will send, you should use the Table API, but that means they will have to use the right tables and have the same column names as your column in ServiceNow.
If you want to accept the JSON as is and simply provide the third party with an endpoint, then you would have to build a Scripted REST APIs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 01:59 PM
Hi Miles, how are you receiving that JSON? Is it using a scripted rest API? Or you simply have that JSON format and do not yet know how you will import it in ServiceNow?
If what you are receiving is a string, then you can convert it to a javascript object using JSON.parse(your_string_variable). Then using that javascript object there are many things you can do depending on what you want to do with the payload.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 07:12 AM
Hi Laurent,
We are not receiving the payload yet. The 3rd party has not completed building the integration from their side, but provided this JSON as an example of the final format.
According to the Servicenow documentation, we can access the JSON api via a url formatted similarly to:
https://your_instance.service-now.com/table_name.do?JSONv2&sysparm_action=insert
I had planned to provide the 3rd party with this URL once they were ready, but I have been trying to insert records via this URL and am getting errors in response. It appears that SN is expecting a different JSON format.
I'm guessing I'm going down the wrong road here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 08:43 AM
Hi Miles
Where will the communication get initiated? So
- Is the 3rd Party Tool going to push data direct to the Instance, OR
- Is the Instance going to the 3rd Party Tool to pull data
If it's number one then you can mock how the REST API and JSON input can behave by using the REST API Explorer (instancename.service-now.com/$restapi.do). You can also refer to the API here: https://developer.servicenow.com/app.do#!/rest_api_doc?v=helsinki&id=c_TableAPI
Should it be the other way, then you can refer to Outbound REST web service to pull data from the 3rd Party Tool. Once you get the data into a variable you can utilise the JSON object in JavaScript to read from it, like so:
var inputString = '{...}'; // JSON from external tool
var inputObj = JSON.parse(inputString); // create a JSON object
inputObj.user.email // getting a value from the response
Hope this helps.
Shahid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-06-2017 01:48 PM
Hi Miles,
As Shahid, if you can have control on what the third party will send, you should use the Table API, but that means they will have to use the right tables and have the same column names as your column in ServiceNow.
If you want to accept the JSON as is and simply provide the third party with an endpoint, then you would have to build a Scripted REST APIs