Can we send multiple records to Service Now within a single REST request?

Kaushik Muley1
Giga Contributor

As per the requirement, the third party tool is supposed to send multiple records in a single REST request.
Can Service Now import set API consume the multiple record JSON to create/update records on target table?

If yes, what should be the format of JSON string?

As per the initial analysis, I found the wiki article on JSONv2, but it does not seem to be working with REST request.

1 ACCEPTED SOLUTION

Yes, a scripted REST API is going to be a better way to go in this case (over a processor). The biggest advantage is that you can use versioning so one app can continue to use v1 (perhaps with no URI parameters) while another app can use v2 (with two URI parameters) simultaneously. Processors cannot do that. You need to maintain two separate processors which can be cumbersome. There are other advantages as well.



Scripted REST APIs


Check Episode 23 here: TechNow Episode List  


View solution in original post

10 REPLIES 10

kaushalpragnya
Kilo Explorer

I tried with the following code



(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response)


{


var gr;


var requestBody = request.body;


var requestData = requestBody.data; //May be an array or a single object


if (requestData instanceof Array)


{


  gr=new GlideRecord('u_samplerest');


    gr.initialize();  


 


      for(i=0;i<requestData.length;i++)


  {  


          gr.country=requestData[i].country;


          gr.company=requestData[i].company;


          gr.employee_number=requestData[i].employeenumber;


      gr.insert();


  }


  }


else


{    


    gr.country=requestData.country;


          gr.company=requestData.company;


    gr.employee_number=requestData.employeenumber;


    gr.insert();


        }


   


})(request, response);