ServiceNow Service Catalog API Cart issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2018 08:19 AM
We have written a integration with ServiceNow to create Service Request ticket on ServiceNow using Service Catalog API - https://docs.servicenow.com/bundle/jakarta-application-development/page/integrate/inbound-rest/conce....
Background
The ticket creation process that is provided by Service Catalog API is two steps process :
- Add an item to cart using API - /sn_sc/servicecatalog/items/{sys_id}/add_to_cart
- Submit order using API - /sn_sc/servicecatalog/cart/submit_order
Issue
We are using above two APIS for ticket creation. Also we are using a single user for authentication in our integration. The issue we are facing is if two concurrent request comes for adding item to cart, they both are added to the same cart which results in creation of single ticket. Check below detail:
Example/Naming convention
Admin user for authentication = John.Doe
Request from our integration — IREQ
ServiceNow ServiceNow Request — REQ and RITM
Scenario
- Integration receive an request IREQ1 and it sends one add item request to the add_to_cart API using user John.Doe and item is added to cart.
- Even before integration submits the cart for the first request IREQ1, integration receives a concurrent request IREQ2 which is sent to the add_to_cart API using the user John.Doe, and item is added to the same cart created by first request IREQ1 — which is problem, here we expect a separate cart to be created for new request from our integration.
- Integration hit the submit order API, for first request IREQ1 but it results in creation of a ticket with two Requested Items (RITMS) as the cart contains two request (REQ1 with RITM1 and RITM2)
- Integration hit the submit order API, for second request but it receives 400 Bad Request error (Cart is empty!) because cart was never created for the second request.
Question
- Is there a way by which we can send any parameter in REST request so that it distinguishes the two requests i.e. IREQ1 and IREQ2 and creates separate cart and ticket for both.
- We come across a thread(https://community.servicenow.com/thread/285856) on the ServiceNow community which talks about the same issue and a possible solution. Is that the best way to solve the issue?
- Labels:
-
Integrations
- 4,012 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2018 06:55 AM
Arun,
The REST APIs are given for the Default Cart usecases. The usecase mentioned is not supported by the present REST APIs.
But we do support the usecase in our scripting layer.
So, you can build your own Scripted REST API and for each request create a new Cart(Creating a new Cart is by passing a new Cart name to it) So you can use timestamp for your usecase.
Now use this cart to order your item. That way every time a request come, the cart is newly created.
Refer to the API supported https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=sn_sc-namespace
Thanks
Shouvik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2018 08:36 AM
Hi Shovik,
We tried below two approaches using the mentioned CartJS API but none of them are working for our use case:
1. We have a requirement to create one REQ and multiple RITM linked to it. I am using below script code to add multiple catalog item to the cart:
var cart = new sn_sc.CartJS();
cart.addToCart(item1);
cart.addToCart(item2);
cart.submitOrder(submitRequest);
In this case only first item is added to the cart and second item is ignored. It results in generating a single REQ with single RITM.
2. As used in the Buy API I tried creating a cart with unique id. But in this case, an REQ is created with no associated RITM. It seems like item is not added to the cart. Below is the script code:
var cartId = gs.generateGUID();
var cart = new sn_sc.CartJS(cartId);
cart.addToCart(item1);
cart.submitOrder(submitRequest);
I confirmed with the ServiceNow support team that we can't add multiple item to the single cart.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2018 01:22 PM
Give it a try by putting the cartid in the item1 variable. for example
var cartId = gs.generateGUID();
var item1 =
{
'sysparm_id': '....',
'sysparm_quantity': '1',
'sysparm_cart_name':cartId,
'variables':{
.....
}
};
cart.orderNow(item);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 05:48 AM
Hi Naveen,
Thanks for the reply. We have a requirement to order multiple item in a single request. OrderNow receives only one item.
Update: We contacted ServiceNow Platform team. Below is the response from them:
There is a bug in our code that prevents checkout of custom cart via scoped APIs. It always checks out DEFAULT cart. addToCart API works but not checkout! It’s a java level fix so workaround not possible.