Rest API to order Multiple Items

Michael51
Tera Guru

Hello All,

I have an requirement to create/order Multiple Items as part of our intergation and this is going to be an Inbound Integration , we have 5 items 

order laptop

Access to VPN 

order Mobile 

Order ID 

Order keyboard - in this Item I have to set predefined variable values 

1. Automatic key board - choice to Yes 

we cannot do this as order guide , we need to create as Individual request 

So now I need to create 5 Items via Rest API can you please suggest some solution and Sample script ,  

@Ankur Bawiskar @Voona Rohila @jaheerhattiwale 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Michael51 

I believe you want all 4/ 5 RITMs in same REQ

I created blog for this couple of years ago. have a look

If it helps please mark the blog as helpful

Multiple RITMs in same Request Using CartAPI 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

jaheerhattiwale
Mega Sage
Mega Sage

@Michael51 Create a scripted rest api to add the custom code to it and trigger the api from outside the servicenow as you wish.

 

Send the Request body to the api like below 

[
		{
			"catalog_item_sys_id": "<order laptop CAT ITEM SYS ID HERE>"
		},
		{
			"catalog_item_sys_id": "<Access to VPN CAT ITEM SYS ID HERE>"
		},
		{
			"catalog_item_sys_id": "<order Mobile CAT ITEM SYS ID HERE>"
		},
		{
			"catalog_item_sys_id": "<Order ID CAT ITEM SYS ID HERE>"
		},
		{
			"catalog_item_sys_id": "<Order keyboard CAT ITEM SYS ID HERE>",
			"<Automatic key board VARIABLE NAME HERE>": "Yes"
		}
	]

 

Steps:

1. Go to "Scripted rest api" module

jaheerhattiwale_0-1685597484769.png

 

2. Create new scripted rest api

jaheerhattiwale_1-1685597508200.png

 

3. Scroll down to see the related list

jaheerhattiwale_2-1685597568295.png

 

4. create a new scripted rest resource

jaheerhattiwale_3-1685597667073.png

 

5. Add below code to scripted rest resource

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

    var requestBody = request.body.data;
    for (var i = 0; i < requestBody.length; i++) {
        var cart = new Cart();
        var item = cart.addItem(requestBody[i].catalog_item_sys_id);

        var keys = Object.keys(requestBody[i]);

        for (var j = 0; j < keys.length; j++) {
            if (keys[j] != "catalog_item_sys_id") {
                cart.setVariable(item, keys[j], requestBody[i][keys[j]]);
            }
        }

        var placeOrder = cart.placeOrder();
    }

})(request, response);

 

Please mark as correct answer if this solves your issue.

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

@Michael51 

I believe you want all 4/ 5 RITMs in same REQ

I created blog for this couple of years ago. have a look

If it helps please mark the blog as helpful

Multiple RITMs in same Request Using CartAPI 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Thanks for your reply Ankur , It should be individual Request and RITM , I mean each item each request and RITM

@Michael51 

then you can use cart API and submit the individual REQ and RITM

what did you start with?

check these links

Submit a catalog item through Email inbound action 

you can also use flow designer for this

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

Thanks Ankur , Can I have sample fot flow designer?