Service Catalog API - POST /sn_sc/servicecatalog/cart/{cart_item_id}

This method edits and updates any item in the cart.

URL format

Versioned URL: /api/sn_sc/v1/servicecatalog/cart/{cart_item_id}

Default URL: /api/sn_sc/servicecatalog/cart/{cart_item_id}

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, seeREST response codes.

Table 4. Status codes
Status code Description
201 Indicates that the request completed successfully and that the item is added to the cart.
400 Following three 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 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

Table 5. Request body parameters
Parameter Description
sysparm_quantity Specifies the quantity of the item to update the cart (required parameter).
variables Object consisting of all variable names and their corresponding valid values. Provide values for all the mandatory variables.
Table 6. Response body parameters
Parameter Description
cart_id Specifies the sys_id of the cart.
subtotal_price Specifies the subtotal of the cart.
subtotal_recurring_frequency Specifies the recurring frequency subtotal of the cart.
subtotal_recurring_price Specifies the recurring price subtotal of the cart.
total_title Specifies the title for total field on page.
show_subtotal_price Specifies Boolean value to show or not show subtotal price.
subtotal_title Specifies the title for subtotal field on page.
monthly, weekly, daily Array of item details classified by recurring frequencies of the items in the cart.
  • subtotal_price: Specifies the subtotal of the frequency block.
  • subtotal_recurring_frequency:Specifies the recurring frequency subtotal of the frequency block.
  • subtotal_recurring_price: Specifies the recurring price subtotal of the frequency block.
  • total_title: Title for total field on the frequency block.
items Array consisting of details of all the items in the cart.
  • catalog_item_id: sys_id of the item in the cart.
  • variables:Object consisting of all the variable names and corresponding values for the item in the cart.
  • quantity: Quantity of the item in the cart.
  • localized_price: Price of the item in local currency.
  • price: Price of the item.
  • localized_recurring_price: Recurring price of the item in local currency.
  • recurring_price: Recurring price of the item.
  • recurring_frequency: Recurring frequency of the item.
  • item_name: Name of the item in the cart.
  • cart_item_id:sys_id of the item in the cart.
  • delivery_time:Delivery time of the item.

Sample cURL request

curl "https://instance.service-now.com/api/sn_sc/v1/servicecatalog/cart/183f0297db21120064301150f0b8f5fe" \
--request POST \
--header "Accept:application/json" \
--user 'admin':'admin'
{
   "result":{
      "cart_id":"616ebdb8db71120076861150f0b8f552",
      "subtotal_price":"$9,599.88",
      "subtotal_recurring_frequency":"Monthly",
      "subtotal_recurring_price":"$348.00",
      "total_title":"Total",
      "monthly":{
         "subtotal_price":"$9,599.88",
         "subtotal_recurring_frequency":"Monthly",
         "subtotal_recurring_price":"$348.00",
         "total_title":"Total",
         "items":[
        {
            "catalog_item_id":"0d08837237153000158bbfc8bcbe5d02",
            "variables":{
                "Monthly data allowance":"500MB",
                "Storage":"16GB",
                "Color":"Black",
                "Allocated carrier":"AT & T Mobility",
                "Contract duration":"18 Months"
            },
               "quantity":"12",
               "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":"a21ffdb0db71120076861150f0b8f560",
               "delivery_time":"2 Days"			//	Check this
            }
         ],
         "show_subtotal_price":"true",
         "subtotal_title":"Subtotal"
      },
      "show_subtotal_price":"true",
      "subtotal_title":"Subtotal"
   }
}

Sample Python request

#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/cart/183f0297db21120064301150f0b8f5fe'

# 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 201
if response.status_code != 201: 
    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" ?>
<root>
    <result>
        <cart_id>616ebdb8db71120076861150f0b8f552</cart_id>
        <subtotal_price>$9,599.88</subtotal_price>
        <subtotal_recurring_frequency>Monthly</subtotal_recurring_frequency>
        <subtotal_recurring_price>$348.00</subtotal_recurring_price>
        <total_title>Total</total_title>
        <monthly>
            <subtotal_price>$9,599.88</subtotal_price>
            <subtotal_recurring_frequency>Monthly</subtotal_recurring_frequency>
            <subtotal_recurring_price>$348.00</subtotal_recurring_price>
            <total_title>Total</total_title>
            <items>
                <catalog_item_id>0d08837237153000158bbfc8bcbe5d02</catalog_item_id>
                <variables>
                    <Monthly data allowance>500MB</Monthly data allowance>
                    <Storage>16GB</Storage>
                    <Color>Black</Color>
                    <Allocated carrier>AT & T Mobility</Allocated carrier>
                    <Contract duration>18 Months</Contract duration>
                </variables>
                <quantity>12</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>a21ffdb0db71120076861150f0b8f560</cart_item_id>
                <delivery_time>2 Days</delivery_time>
            </items>
            <show_subtotal_price>true</show_subtotal_price>
            <subtotal_title>Subtotal</subtotal_title>
        </monthly>
        <show_subtotal_price>true</show_subtotal_price>
        <subtotal_title>Subtotal</subtotal_title>
    </result>
</root>