# Cart endpoints

# Get cart

Get the customer' cart.

# Endpoint

GET /cart.js

# Examples

Axios request

axios.post('/cart.js')
.then((response) => {
    this.$root.cart = response.data
})
.catch(e => {
    console.log(e.response.data)
})

Successful response

{
    "id": 1682439003100965,
    "attributes": [],
    "original_total_price": 69800,
    "total_discount": 10000,
    "total_price": 59800,
    "tax_price": 11960,
    "tax_rate": 2500,
    "total_weight": 2264,
    "item_count": 2,
    "items": [
        {
            "id": "mRjW0Mz3redAlp961XdQaXnJGN57gxBk",
            "title": "Basic T-shirt - Black",
            "price": 69800,
            "line_price": 34900,
            "quantity": 2,
            "inventory_quantity": null,
            "sku": null,
            "grams": null,
            "vendor": "Your Shop",
            "properties": null,
            "variant_id": 1612407237867184,
            "product_id": 1612407237849627,
            "url": "https:\/\/your-shop.codefort.io\/products\/basic-t-shirt?variant=1612407237867184",
            "image": "https:\/\/files.codefort.com\/your-shop\/images\/products\/1024x1024\/5d35824e372de.jpg",
            "handle": "basic-t-shirt",
            "requires_shipping": true,
            "product_title": "Basic T-shirt",
            "product_description": null,
            "product_type": "T-shirts",
            "variant_title": "Black",
            "variant_options": null,
            "parent_row_id": null,
            "is_recurring": false
        }
    ],
    "requires_shipping": true,
    "has_free_shipping": false,
    "is_recurring": false,
    "voucher_code": "SALE100"
}

# Add to cart

Add a variant to the customer' cart.

# Endpoint

POST /cart/add.js

# Parameters

Name Required Default
id true
quantity false 1
clear false

id
The id of a variant.

quantity
The quantity of the specified variant you want to add to the cart.

clear
The parameter can have one of these three values 1, product, products.

  • 1 - Clear the full cart incl. any rows and discounts.

  • product - Clear the cart for any rows that has a variant from the same product that you are adding to the cart.

  • products - Clear the cart for all existing products, but keep any discounts.

# Examples

Axios request

axios.post('/cart/add.js', {
    id: 1612407237867184
    quantity: 2
})
.then((response) => {
    console.log(response.data)
})
.catch(e => {
    console.log(e.response.data)
})

Successful response

{
    "id": 1682439003100965,
    "attributes": [],
    "original_total_price": 69800,
    "total_discount": 0,
    "total_price": 69800,
    "tax_price": 11960,
    "tax_rate": 2500,
    "total_weight": 2264,
    "item_count": 2,
    "items": [
        {
            "id": "mRjW0Mz3redAlp961XdQaXnJGN57gxBk",
            "title": "Basic T-shirt - Black",
            "price": 69800,
            "line_price": 34900,
            "quantity": 2,
            "inventory_quantity": null,
            "sku": null,
            "grams": null,
            "vendor": "Your Shop",
            "properties": null,
            "variant_id": 1612407237867184,
            "product_id": 1612407237849627,
            "url": "https:\/\/your-shop.codefort.io\/products\/basic-t-shirt?variant=1612407237867184",
            "image": "https:\/\/files.codefort.com\/your-shop\/images\/products\/1024x1024\/5d35824e372de.jpg",
            "handle": "basic-t-shirt",
            "requires_shipping": true,
            "product_title": "Basic T-shirt",
            "product_description": null,
            "product_type": "T-shirts",
            "variant_title": "Black",
            "variant_options": null,
            "parent_row_id": null,
            "is_recurring": false
        }
    ],
    "requires_shipping": true,
    "has_free_shipping": false,
    "is_recurring": false,
    "voucher_code": ""
}

Failed response

{
    "message":"The given data was invalid.",
    "errors": {
        "id": [
            "The specified id does not exist.",
        ]
    }
}

# Update cart item

Update quantity for a cart item in the customer' cart.

# Endpoint

POST /cart/update.js

# Parameters

Name Required
id true
quantity true

id
The id of a cart item.

quantity
The new quantity you want for cart item.
Specify 0 to delete the cart item.

# Examples

Axios request

axios.post('/cart/update.js', {
    id: 'mRjW0Mz3redAlp961XdQaXnJGN57gxBk'
    quantity: 3
})
.then((response) => {
    console.log(response.data)
})
.catch(e => {
    console.log(e.response.data)
})

Successful response

{
    "id": "mRjW0Mz3redAlp961XdQaXnJGN57gxBk",
    "title": "Basic T-shirt - Black",
    "price": 69800,
    "line_price": 34900,
    "quantity": 3,
    "inventory_quantity": null,
    "sku": null,
    "grams": null,
    "vendor": "Your Shop",
    "properties": null,
    "variant_id": 1612407237867184,
    "product_id": 1612407237849627,
    "url": "https:\/\/your-shop.codefort.io\/products\/basic-t-shirt?variant=1612407237867184",
    "image": "https:\/\/files.codefort.com\/your-shop\/images\/products\/1024x1024\/5d35824e372de.jpg",
    "handle": "basic-t-shirt",
    "requires_shipping": true,
    "product_title": "Basic T-shirt",
    "product_description": null,
    "product_type": "T-shirts",
    "variant_title": "Black",
    "variant_options": null,
    "parent_row_id": null,
    "is_recurring": false
}

Failed response

{
    "message":"The given data was invalid.",
    "errors": {
        "id": [
            "The specified id does not exist.",
        ]
    }
}