Service Catalog API - POST /sn_sc/servicecatalog/items/{sys_id}/add_to_cart

This method adds an item to the cart of the current user.

URL format

Versioned URL: /api/sn_sc/v1/servicecatalog/items/{sys_id}/add_to_cart

Default URL: /api/sn_sc/servicecatalog/items/{sys_id}/add_to_cart

Supported request parameters

Table 1. Parameters
Parameter Description
None

Headers

The following request and response headers apply to this HTTP action only, or apply to this action in a distinct way. For a list of general headers used in the REST API, see Supported REST API headers.

Table 2. Request headers
Header Description
None
Table 3. Response headers
Header Description
None

Status codes

The following status codes apply to this HTTP action. For a list of possible status codes used in the REST API, see REST response codes .

Table 4. Status codes
Status code Description
200 Indicates that the request completed successfully and the item is added to the cart. And the response contains all the details of the items currently in the cart.
400 The following errors can occur:
  • Invalid quantity value:Indicates that either the sysparm_quantity parameter is not provided or contains invalid value.
  • Security constraints prevent ordering of Item:Indicates that either the Cart Item ID specified in the path parameters is either invalid or the user does not have access to the item.
  • Mandatory Variables are required:Indicates that one or more of the mandatory variable values is not provided in the request.

Request and response body

The following are parameters for the request body.

Table 5. Values required in the request body
Parameter Description
sysparm_quantity Specifies the quantity of the item to be added to the cart. It is mandatory to provide this parameter and make sure that it is a non-negative number.
variables Object consisting of all variable names and their corresponding valid values. Provide values for all the mandatory variables, as shown in the following example.
The following are JSON or XML values included in the response.
Table 6. Values returned in the response body
Parameter Description
cart_id Specifies the sys_id of the cart.
subtotal Specifies the subtotal of the items.
items Array consisting of details of all the items in the cart.
catalog_item_id Specifies the sys_id of the item in the cart.
quantity Specifies the quantity of the item in the cart.
localized_price Specifies the price of the item in local currency of the user.
price Specifies the price of the item.
localized_recurring_price Specifies the recurring price of the item in local currency of the user.
recurring_price Specifies the recurring price of the item.
item_name Specifies the name of the item in the cart.
cart_item_id Specifies the sys_id of the item in the cart.

Sample cURL request and response

curl "https://instance.service-now.com/api/sn_sc/v1/servicecatalog/items/0d08837237153000158bbfc8bcbe5d02/add_to_cart" \
--request POST \
--header "Accept:application/json" \
--user 'admin':'admin'
{
   "result":{
      "cart_id":"0951c597db21120064301150f0b8f5cf",
      "subtotal":"$1,599.98",
      "items":[
         {
            "catalog_item_id":"0d08837237153000158bbfc8bcbe5d02",
            "quantity":"2",
            "localized_price":"$799.99",
            "price":"$799.99",
            "recurring_frequency":"Monthly",
            "localized_recurring_price":"$30.00",
            "recurring_price":"$29.00",
            "item_name":"Apple iPhone 5",
            "cart_item_id":"ac61c597db21120064301150f0b8f5f9"
         }
      ]
   }
}

Sample Python request and response

#Need to install requests package for python
#easy_install requests
import requests

# Set the request parameters
url = 'https://instance.service-now.com/api/sn_sc/v1/servicecatalog/items/0d08837237153000158bbfc8bcbe5d02/add_to_cart'

# Eg. User name="admin", Password="admin" for this code sample.
user = 'admin'
pwd = 'admin'

# Set proper headers
headers = {"Content-Type":"application/xml","Accept":"application/xml"}

# Do the HTTP request
response = requests.post(url, auth=(user, pwd), headers=headers  )

# Check for HTTP codes other than 200
if response.status_code != 200: 
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:',response.json())
    exit()

# Decode the JSON response into a dictionary and use the data
data = response.json()
print(data)
<?xml version="1.0" encoding="UTF-8"?>
<response>
    <result>
        <cart_id>818245d7db21120064301150f0b8f5ba</cart_id>
        <subtotal>$1,599.98</subtotal>
        <items>
            <catalog_item_id>0d08837237153000158bbfc8bcbe5d02</catalog_item_id>
            <quantity>2</quantity>
            <localized_price>$799.99</localized_price>
            <price>$799.99</price>
            <recurring_frequency>Monthly</recurring_frequency>
            <localized_recurring_price>$30.00</localized_recurring_price>
            <recurring_price>$29.00</recurring_price>
            <item_name>Apple iPhone 5</item_name>
            <cart_item_id>ab82c597db21120064301150f0b8f5fa</cart_item_id>
        </items>
    </result>
</response>