Inbound REST Scripted Web Service

harishdasari
Tera Guru

Hi

In Scripted REST web service, when Third party system sends response, it should come into servicenow.

I have created staging table and custom table.

Here Issue is how can I get values into staging table and how to make transformed into custom table.

can anyone please let me know the steps how to acheive this using scripted REST inbound web service

Thanks

1 ACCEPTED SOLUTION

Hi Harish,



I developed it in my demo instance and here are the steps. Here you go:



1) Only POST and GET methods are supported.



2) Create web service import set, transform map and field map etc


a) Name of web service - REST API Import Set


b) Label - u_rest_api_import_set


c) 2 fields for testing Short Description(u_short_description) and Incident Number(u_incident_number)


d) Transform map


e) 2 Field maps for the above 2 fields with coalesce on incident number field.



3) Consuming the API: I tested this using Hurl.it - Make HTTP requests . This testing will allow you to understand how the client/end system will consume your REST API



Screenshot below:



find_real_file.png




a) Method - POST
b) Endpoint - https://instanceName.service-now.com/api/now/import/u_rest_api_import_set


c) Header -


i) Accept -> application/xml OR application/json (Response accepted will be in this format)


ii) Content-Type -> application/xml OR application/json (Request sent to Servicenow will be either XML or JSON based on this)


d) Request Body - this you will have to tell the client/user that you will accept in this sample request body.


{


"u_short_description": "hello122",


"u_incident_number" : "INC0010043"


}


e) Authentication - create a user with rest role and give id and password in that field. example: user id -> rest.user



Sample Response received as XML:


<?xml version="1.0" encoding="UTF-8"?>
<response>
 
<import_set>ISET0010381</import_set>
 
<staging_table>u_rest_api_import_set</staging_table>
 
<result>
   
<display_value>INC0010043</display_value>
   
<sys_id>2a8c29254f500300fc11fa218110c7df</sys_id>
   
<transform_map>REST API Transform Map</transform_map>
   
<record_link>https://instanceName.service-now.com/api/now/table/incident/2a8c29254f500300fc11fa218110c7df</record_link>
   
<display_name>number</display_name>
   
<table>incident</table>
   
<status>inserted</status>
 
</result>
</response>



Sample Response received as JSON:


{


  "import_set": "ISET0010381",


  "staging_table": "u_rest_api_import_set",


  "result": [


      {


          "transform_map": "REST API Transform Map",


          "table": "incident",


          "display_name": "number",


          "display_value": "INC0010043",


          "record_link": "https://instanceName.service-now.com/api/now/table/incident/2a8c29254f500300fc11fa218110c7df",


          "status": "ignored",


          "sys_id": "2a8c29254f500300fc11fa218110c7df",


          "status_message": "No field values changed"


      }


  ]


}



You can explore further on this as per your requirement.



Endorse the content if you feel this was helpful. How to Endorse Content



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Hi Harish,



I developed it in my demo instance and here are the steps. Here you go:



1) Only POST and GET methods are supported.



2) Create web service import set, transform map and field map etc


a) Name of web service - REST API Import Set


b) Label - u_rest_api_import_set


c) 2 fields for testing Short Description(u_short_description) and Incident Number(u_incident_number)


d) Transform map


e) 2 Field maps for the above 2 fields with coalesce on incident number field.



3) Consuming the API: I tested this using Hurl.it - Make HTTP requests . This testing will allow you to understand how the client/end system will consume your REST API



Screenshot below:



find_real_file.png




a) Method - POST
b) Endpoint - https://instanceName.service-now.com/api/now/import/u_rest_api_import_set


c) Header -


i) Accept -> application/xml OR application/json (Response accepted will be in this format)


ii) Content-Type -> application/xml OR application/json (Request sent to Servicenow will be either XML or JSON based on this)


d) Request Body - this you will have to tell the client/user that you will accept in this sample request body.


{


"u_short_description": "hello122",


"u_incident_number" : "INC0010043"


}


e) Authentication - create a user with rest role and give id and password in that field. example: user id -> rest.user



Sample Response received as XML:


<?xml version="1.0" encoding="UTF-8"?>
<response>
 
<import_set>ISET0010381</import_set>
 
<staging_table>u_rest_api_import_set</staging_table>
 
<result>
   
<display_value>INC0010043</display_value>
   
<sys_id>2a8c29254f500300fc11fa218110c7df</sys_id>
   
<transform_map>REST API Transform Map</transform_map>
   
<record_link>https://instanceName.service-now.com/api/now/table/incident/2a8c29254f500300fc11fa218110c7df</record_link>
   
<display_name>number</display_name>
   
<table>incident</table>
   
<status>inserted</status>
 
</result>
</response>



Sample Response received as JSON:


{


  "import_set": "ISET0010381",


  "staging_table": "u_rest_api_import_set",


  "result": [


      {


          "transform_map": "REST API Transform Map",


          "table": "incident",


          "display_name": "number",


          "display_value": "INC0010043",


          "record_link": "https://instanceName.service-now.com/api/now/table/incident/2a8c29254f500300fc11fa218110c7df",


          "status": "ignored",


          "sys_id": "2a8c29254f500300fc11fa218110c7df",


          "status_message": "No field values changed"


      }


  ]


}



You can explore further on this as per your requirement.



Endorse the content if you feel this was helpful. How to Endorse Content



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,



Thanks for the response.



I have created Scripted inbound service and Post inbound integation.


find_real_file.png



As shown in the screenshot, this is the code I have written into scripted REST web-service to load into servicenow tables.


I am inserting the values into staging table, i have highlighted in screenshot.


this values which I specified in the request are "u_to", "u_from", u_status", u_messageid".


third party will send this parameters in JSON format. this should save in servicenow.


I have tried your method, but that doesn't work in this case.


Thank you.



find_real_file.png


Hi Harish,



This is REST API Import Set so why have you created scripted rest api.


In your question you mentioned that you wanted custom staging table and then transform into target table.



I don't get why you are consuming another REST Message in this scripted rest api script.


Can you explain your requirement?



Scripted REST API will be created in Servicenow and endpoint given to third party to consume that.


Import Set REST API endpoint will be created in Servicenow and endpoint will be given to third party to consume that.



you are creating the api and you are consuming it. I am confused here.



Regards


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

oh, Thank you for clarifying Ankur.  



I am doing mistake here. Thanks for correcting me.



Just for some clarification could you please let me know   in which   cases we will be using the scripted API, because i got confused and doing the coding to fulfill the requirement.



Thank you.


Hi Harish,



Scripted REST API will be used when some third party wants to consume REST API developed in Servicenow to either fetch some information or they want to update something in Servicenow.


GET method helps third party to get the details


POST method creates record to custom table which will be present in the script section


PUT method will update the record which you will handle in script section.



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader