> This page is for Developer.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.bigcommerce.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.bigcommerce.com/_mcp/server.

# Cart API - Hands-on Lab

Lesson 7 of 26 · 45 min

## Cart API

Server-to-Server Cart API allows for a cart to be created using BigCommerce cart logic. The existing BigCommerce front-end cart can be bypassed.In this activity, you will use the Server-to-Server Cart API to view the details of a cart using an API REST client. You will also use the Cart API to create, modify, and delete a cart as well as create redirect URLs.

### **In this lab, you will:**

* Create a Cart
* Add cart line items
* GET a cart
* Update cart line items
* Delete cart line items
* Update customer ID
* Create a redirect URL
* Delete a cart

### Prerequisites

* BigCommerce store (sandbox or live)
* API credentials for the store
* REST client (Postman)

## Create a cart with a simple product (a product without option selections)

1. **Open** Postman
2. **Click** the No Environment dropdown in the upper-right
3. **Select** the environment you created in the previous lab
4. **Copy** and **paste** the request below into Postman

```http showLineNumbers={false}
https://api.bigcommerce.com/stores/{{store_hash}}/v3/carts
```

> **Info**
>
> If you created your environment correctly in the previous lab, `{{store_hash}}` will use your store's store hash automatically.

5. **Copy** and **paste** the code below into the body section of Postman

```json showLineNumbers={false}
{
    "line_items": [
            {
                "quantity": 1,
                "product_id": {product_id}
            }
    ]
}
```

6. **Replace** `{product_id}` with the ID of the product to be added to cart
7. **Select** POST next to the request URL
8. **Click** the Send button
9. **Observe** response
10. **Copy** and **save** the `cart_id` for use in the next steps

## Create a cart with a complex product, a custom item, and a gift certificate

1. **Copy** and **paste** the request below into Postman

```http showLineNumbers={false}
https://api.bigcommerce.com/stores/{{store_hash}}/v3/carts/{cart_id}items
```

> **Info**
>
> If you created your environment correctly in the previous lab, `{{store_hash}}` will use your store's store hash automatically.

2. **Replace** `{cart_Id}` with the cart\_id created in the previous steps
3. **Copy** and **paste** the code below into the Body section of Postman

```json showLineNumbers={false}
{
    "line_items": [
      {
         "quantity": 1,
         "product_id": {product_id},
         "variant_id": {variant_id},
         "option_selections": [
           {
             "option_id": {option_id},
             "option_value": {option_value}
           },
           {
             "option_id": {option_id},
             "option_value": {option_value}
           }
         ]
      }
    ],
    "gift_certificates": [
      {
         "name": "Happy Birthday",
         "theme": "Birthday",
         "amount": 15,
         "quantity": 1,
         "sender": {
           "name": "Jane Doe",
           "email": "janedoe@email.com"
         },
         "recipient": {
           "name": "John Smith",
           "email": "joesmith@email.com"
         },
         "message": "Happy Birthday John!"
      }
    ],
    "custom_items": [
      {
        "sku": "SKU123",
        "name": "Custom Product",
        "quantity": 1,
        "list_price": 25
      }
    ]
}
```

4. **Replace** `{product_id}` with the ID of the product to be added to cart
5. **Replace** `{variant_id}`, `{option_id}`, and `{option_value}` with the appropriate IDs for the
   product being added to cart
6. **Select** POST next to the request url
7. **Click** the Send button
8. **Observe** response

## GET a Cart

1. **Copy** and **paste** the request below into Postman

```http showLineNumbers={false}
https://api.bigcommerce.com/stores/{{store_hash}}/v3/carts/{cart_id}
```

> **Info**
>
> If you created your environment correctly in the previous lab, `{{store_hash}}` will use your store's store hash automatically.

2. **Replace** `{cart_id}` with the cart ID copied in the previous steps
3. **Select** GET next to the request URL
4. **Click** the Send button
5. **Observe** response and copy one of the line item IDs for use in the next steps

## Update Cart Line Items

> **Info**
>
> Currently only updating the item price and quantity are supported.
>
> If a variant needs to be changed or updated, the product will need to be removed and re-added to the cart with the correct variants using the Add Cart Line Items endpoint.

1. **Copy** and **paste** the request below into Postman

```http showLineNumbers={false}
https://api.bigcommerce.com/stores/{{store_hash}}/v3/carts/{cart_id}/items/{item_id}
```

> **Info**
>
> If you created your environment correctly in the previous lab, `{{store_hash}}` will use your store's store hash automatically.

2. **Replace** `{cart_id}` with the Cart ID created in the previous steps
3. **Replace** `{item_id}` with the Item ID copied in the previous steps
4. **Copy** and **paste** the code below into the Body section of Postman

```json showLineNumbers={false}
{
    "line_item": {
    "quantity": 5,
    "product_id": {product_id},
    "list_price": 100.0
    }
}
```

5. Replace `{product_id}` with the product ID to be updated
6. **Select** PUT next to the request URL
7. **Click** the Send button
8. **Observe** response

## DELETE Cart Line Items

> **Info**
>
> Removing the last `line_item` in the Cart deletes the Cart.

1. **Copy** and **paste** the request below into Postman

```http showLineNumbers={false}
https://api.bigcommerce.com/stores/{{store_hash}}/v3/carts/{cart_id}/items/{items_id}
```

> **Info**
>
> If you created your environment correctly in the previous lab, `{{store_hash}}` will use your store's store hash automatically.

2. **Replace** `{cart_id}` with the Cart ID created in the previous activity
3. **Replace** `{item_id}` with the item to be deleted
4. **Select** DELETE next to the request url
5. **Click** the Send button
6. **Observe** response and line item deleted

## Update a cart to change the customer ID assigned to the cart

1. **Copy** and **paste** the request below into Postman

```http showLineNumbers={false}
https://api.bigcommerce.com/stores/{{store_hash}}/v3/carts/{cart_id}
```

> **Info**
>
> If you created your environment correctly in the previous lab, `{{store_hash}}` will use your store's store hash automatically.

2. **Replace** `{cart_id}` with the Cart ID created in the previous steps
3. **Copy** and **paste** the code below into the Body section of Postman

```json showLineNumbers={false}
{
    "customer_id": {customer_id}
}
```

4. **Replace** `{customer_id}` with the ID of a customer in the store
5. **Select** PUT next to the request URL
6. **Click** the Send button
7. **Observe** response and customer ID updated

## Create a Redirect URL

1. **Copy** and **paste** the request below into Postman

```http showLineNumbers={false}
https://api.bigcommerce.com/stores/{{store_hash}}/v3/carts/{cart_id}/redirect_urls
```

> **Info**
>
> If you created your environment correctly in the previous lab, `{{store_hash}}` will use your store's store hash automatically.

2. **Replace** `{cart_id}` with the Cart ID created in the previous steps
3. **Select** POST next to the request url
4. **Click** the Send button
5. **Observe** response and redirect URLs created

## Delete a Cart

> **Info**
>
> Once a cart has been deleted it cannot be recovered.

1. **Copy** and **paste** the request below into Postman

```http showLineNumbers={false}
https://api.bigcommerce.com/stores/{{store_hash}}/v3/carts/{cart_id}
```

> **Info**
>
> If you created your environment correctly in the previous lab, `{{store_hash}}` will use your store's store hash automatically.

2. **Replace** `{cart_id}` with the Cart ID to be deleted
3. **Select** DELETE next to the request URL
4. **Click** the Send button
5. **Observe** response and cart deleted