Create order through SN Rest API

wakespirit
Kilo Guru

Dear all,

Hello,

I simply need to place an order from Service Catalog by using SN REST Api, 

The client is a chat bot

  1. the customer want to get its list of available assets in given category ( ex : computer).
  2. From the list of return assets, he will decide for instance to by a certain type of computer
  3. Then an order will be place and created for the item in order to place that Computer order with all details.
  4. The all information of created order should be send back to customer as part of web service response

 

Could you please describe more clearly :

- Which REST API tables will be used in order to complete the  request and how many request should be send ?

( I have seen that order create a Request and Request Item in task table and then a link to sc_req_item table)
 

- How to return to client a formatted return response with collection of placed order information ? is it native or need to create custom web service to merge data in a single response ? 

Thanks for help on this

 

1 ACCEPTED SOLUTION

Hi, Those chocies are into another table not sure the table name may be sys_choice and you can match them with element (name of the variable). Please login to servicenow, open variable type select, then in related list, you can see choices. You can open into new tab by fright click the filter(blue text ) and in url you can get the table name. You need to again query the choice table to get correct choices for that variable.

View solution in original post

9 REPLIES 9

rahulpandey
Kilo Sage

Hi,

To order a service request, servicenow has a separate API 

https://docs.servicenow.com/bundle/jakarta-application-development/page/integrate/inbound-rest/concept/c_ServiceCatalogAPI.html

However, You can also create a scripted rest api, where you can accept array of JSON string and iterate through each using below API

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f'); 
cart.setVariable(item,'os','Linux Red Hat');
var rc = cart.placeOrder(); 
gs.addInfoMessage(rc.number);Details are available here
https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/reference/r_ServiceCatalogScriptAPI.html

 

The sample you provide is handing the shopping cart once you select the product correct ?

But before that what wold be the process for the following

1- Collecting Asset for a given category like "Computer"

2 - From the selected item by user then select all available possible configurable option like Hard drive size, memory size, operating system ( if exist)

3 once the all selection is full at that time only it can be place to shopping cart using your sample

 

So how to handle above steps, which API to be used on each step ?

 

I could not see the Service Catalog API in REST API Explorer, does it exist ?

regards

 

Hi,

1- To get the list of all assets, you can use table apis to get it using GET method.

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/integrate/inbound_rest/concept/c_TableAPI.html

2- To get all the variables available of a particular catalog, you can again query the table api and get all variable from table "item_option_new"

3 - this can be logic be built if, any one variable is blank, then throw an error

I suggest, use scripted rest api with cart api, this gives you more control over data flow and return body.

 

I jsut try the following you mention as  :

 

To get all the variables available of a particular catalog, you can again query the table api and get all variable from table "item_option_new"

I get the root option using this like for instance os-platform, but then how can I get the choice option value inside os-platform variable as in UI it is choice box ?

regards