API handle entire body

Vejdis
Tera Expert

Hello!

 

I'm having a requirement of integrating two systems via api. Normally we handle this via System Import Sets quite easily but the API call that we will recieve now can't be tweaked to fit the standard we have. As such what I want is to just get the entire body, and then handle it via code myself. The body looks like this

 

 

{
  "genericRequestProperty": [
    {
      "content": "string",
      "name": "string"
    }
  ],
  "importHandlerIdentifier": "toHandle",
  "itemToImport": [
    {      
      "id": "123",
      "property": [
        {
            "content": "My header,
            "name": "header"          
        },
        {
            "content": "My description",
            "name": "description"
        },
        {
            "content": "1 - critical",
            "name": "priority"          
        },
        {
            "content": "group1",
            "name": "managerGroup"
        },
		{
			"content": "firstname.lastname@client.com",
			"name": "contact"
		},
		{
			"content": "123",
			"name": "ticketid"
		}
      ],
      "uid": "123"
    }
  ]
}

 

 I won't be able to GET it, they will POST it to us. I would like to be able to get everything in the array itemToImport just as is, into ServiceNow but how should I approach it? Currently I'm trying with postman and sending the API call to a custom table but all the fields are just ending up as empty

1 ACCEPTED SOLUTION

Oliver Stammler
Giga Guru

Hey @Vejdis,
I think your way is absolutely possible. They can POST it to your custom table by using the ootb table REST API. 
Just add the complete JSON to one field and parse everything using an on insert business rule.

Anyways I would recommend to create a scripted REST API (https://docs.servicenow.com/en-US/bundle/tokyo-application-development/page/integrate/custom-web-ser...) to provide a custom endpoint to the other system. Within your scripted REST API you can directly parse the inbound JSON and then process the data. 

In this scenario you do not have to waste a custom table since. 

Best regards

Oli

View solution in original post

2 REPLIES 2

Oliver Stammler
Giga Guru

Hey @Vejdis,
I think your way is absolutely possible. They can POST it to your custom table by using the ootb table REST API. 
Just add the complete JSON to one field and parse everything using an on insert business rule.

Anyways I would recommend to create a scripted REST API (https://docs.servicenow.com/en-US/bundle/tokyo-application-development/page/integrate/custom-web-ser...) to provide a custom endpoint to the other system. Within your scripted REST API you can directly parse the inbound JSON and then process the data. 

In this scenario you do not have to waste a custom table since. 

Best regards

Oli

Thank you very much!

I worked with the scripted API solution, no idea how I have missed that super easy to handle incoming requests. thanks!