Sai Kumar B
Mega Sage
Mega Sage

We can utilize the Service catalog API to raise catalog requests from external applications when integrating third-party applications with ServiceNow.

We'll need two important APIs to submit the request 👇

> Add Item To Cart (POST)

> Submit Order (POST)

STEPS TO REPRODUCE

1.) Open REST API EXPLORER from Application navigator

find_real_file.png

2.) Choose Namespace as sn_sc and Select Add Item To Cart (POST)

find_real_file.png

3.) Upon selecting the Add Item To Cart (POST)

      > To identify the Item Give the Catalog Item sys_id in path parameters 
      >  Provide Request body in the Raw format
      >  For Example, I have selected the OOTB Standard laptop as Catalog Item

find_real_file.png

       >  Now give the request body, which should include the following information:

           sysparm_also_request_for - Optional
           sysparm_quantity - Required. Quantity of the item. Cannot be a negative number.
                                           Data type: Number
           Variables - Name-value pairs of all mandatory cart item variables. Mandatory variables are defined in the associated form.
                                           Data type: String

Sample RAW format

{ 
'sysparm_quantity': 1,
'variables': { 

'acrobat' : 'true',
'photoshop' : 'true',
'Additional_software_requirements' : 'Testing Service catalog API' 

}
}

find_real_file.png

4.) Upon submission you should get the below response

find_real_file.png

5.) Now that the items have been added to the cart, we must submit the request using the Submit Order (POST) API.

find_real_file.png

6.) We can submit without giving any more information in the Request body after selecting the API. The ideal response should be as follows:

find_real_file.png

7.) You can check the Request by navigating to the Request form/RITM form, as shown below.

find_real_file.png

References : 

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/rest/c_ServiceCatalogAPI#r_SCatAPIA...

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/rest/c_ServiceCatalogAPI#servicecat...

Please give your valuable feedback and post comments if any corrections are required 😊

Regards,
Sai Kumar Bolisetty

Community Rising Star 2022

           

 

Comments
Finlay Marsden
Kilo Contributor

Check this out, This might help : https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0686272/MyMercy.com

Mishu
Tera Expert

Cant we do this by using a single API ?

Sai Kumar B
Mega Sage
Mega Sage

@Mishu If you wanna do it via REST API above mentioned is the process, If you want to create Requests from any of the server-side scripts you can use Cart API.

Sample code 

 

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f');  //Pass catalog item sys_id
cart.setVariable(item,'os','Linux Red Hat'); //Set the variable value
var rc = cart.placeOrder();  //Place order
gs.addInfoMessage(rc.number); //Alert the Request number

 

 

chercm
Mega Sage

@Sai Kumar B  where to place the script in the API explorer and i cannot find the cart API on the left of the screen ?

Waffle
Tera Expert

Hello @Sai Kumar B,

 

I put this into a script include to call these 2 APIs, but I ran into an issue where I need to Requested for to be someone else instead of myself after the Request is created. I altered the payload to 

{
        "sysparm_quantity": 1,
        "variables": {
            "comment": "body"
        },
        "sysparm_requested_for": "7c77e1681b2cb4107e327735cc4bcbea"
}
 
I checked the Requested for in the cart is correct, but once the SubmitOrder API runs, the requested for is myself not the Requested for in the cart.
 
Thanks,
LalithaJ
Tera Contributor

Hi,

I see that in this article you simulate the calls from the API explorer within SNOW. but we were to use these calls from an external app, what is the supported authentication/authorization methods supported?

Version history
Last update:
‎04-30-2022 12:22 AM
Updated by: