Add Custom Item to Cart

You will want to add a custom item to the cart to handle things like shipping, taxes and inventory you don't manage with Moltin.

Any requests to add a product to cart will return a collection of cart items.

Custom Cart Items are available via implicit authentication. You should always check each order has the correct details for each item, most importantly, price.

post
Add Custom Item to Cart

https://api.moltin.com/v2/carts/:reference/items
Request
Response
Path Parameters
reference
required
string
A custom reference for this cart created by you
Headers
X-MOLTIN-CURRENCY
optional
string
Specifies the currency to be used for the products in the cart. Your site's default will be used if not specified
Authorization
required
string
The Bearer token to grant access to the API
Body Parameters
type
required
string
custom_item
name
required
string
The name of the custom item
sku
optional
string
The SKU code to use for the custom item
description
optional
string
A description of the custom item
quantity
required
integer
The amount of custom items to add to cart
price.amount
required
integer
The price of the custom item
price.includes_tax
optional
boolean
true if relevant taxes have been included in the price, false if not. Defaults to true
201: Created
{
"data": [
{
"id": "581db51b-d4df-4aff-855d-e8ddbcf81b0c",
"type": "custom_item",
"name": "My Custom Item",
"description": "My first custom item!",
"sku": "my-custom-item",
"image": {
"mime_type": "",
"file_name": "",
"href": ""
},
"quantity": 1,
"manage_stock": false,
"unit_price": {
"amount": 10000,
"currency": "USD",
"includes_tax": true
},
"value": {
"amount": 10000,
"currency": "USD",
"includes_tax": true
},
"links": {},
"meta": {
"display_price": {
"with_tax": {
"unit": {
"amount": 10000,
"currency": "USD",
"formatted": "$100.00"
},
"value": {
"amount": 10000,
"currency": "USD",
"formatted": "$100.00"
}
},
"without_tax": {
"unit": {
"amount": 10000,
"currency": "USD",
"formatted": "$100.00"
},
"value": {
"amount": 10000,
"currency": "USD",
"formatted": "$100.00"
}
}
},
"timestamps": {
"created_at": "2018-05-08T10:11:17.871313413Z",
"updated_at": "2018-05-08T10:11:17.871313413Z"
}
}
}
],
"meta": {
"display_price": {
"with_tax": {
"amount": 57500,
"currency": "USD",
"formatted": "$575.00"
},
"without_tax": {
"amount": 57500,
"currency": "USD",
"formatted": "$575.00"
}
},
"timestamps": {
"created_at": "2018-05-08T10:00:20.171Z",
"updated_at": "2018-05-08T10:11:17.871313413Z"
}
}
}
cURL
JavaScript SDK
Moltin Request
curl -X POST https://api.moltin.com/v2/carts/:reference/items \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \
-d $'{
"data": {
"type": "custom_item",
"name": "My Custom Item",
"sku": "my-custom-item",
"description": "My first custom item!",
"quantity": 1,
"price": {
"amount": 10000
}
}
}'
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
const reference = 'XXXX'
const item = {
name: 'My Custom Item',
sku: 'my-custom-item',
description: 'My first custom item!',
quantity: 1,
price: {
amount: 10000
}
}
Moltin.Cart(reference)
.AddCustomItem(item)
.then(cart => {
// Do something
})
const { MoltinClient } = require('@moltin/request')
const client = new MoltinClient({
client_id: 'X'
})
const reference = 'XXXX'
client
.post(`carts/${reference}/items`, {
type: "custom_item",
name: 'My Custom Item',
sku: 'my-custom-item',
description: 'My first custom item!',
quantity: 1,
price: {
amount: 10000
}
})
.then(cart => {
// Do something...
})
.catch(console.error)