Get a Cart
note
By default, the cart name is Cart
, but you can update the name for the cart. Ensure that the string length is greater than or equal to one. Follow the safe character guidelines for name and description naming. For more information about cart id naming requirements, see Safe Characters.
GET
Get a Cart by reference
https://api.moltin.com/v2/carts/:reference
Path Parameters:
Name | Required | Type | Description |
---|---|---|---|
reference | Required | string | A custom reference for this cart created by you. |
Headers:
Name | Required | Type | Description |
---|---|---|---|
Authorization | Required | string | The Bearer token to grant access to the API. |
Query Parameters:
Name | Required | Type | Description |
---|---|---|---|
include | Optional | string | Comma-delimited string of entities that can be included - valid options: items . |
200 OK
{
"data": {
"id": "360acb59-3fb7-4150-8066-ea54e850015b",
"type": "cart",
"links": {
"self": "https://api.moltin.com/carts/360acb59-3fb7-4150-8066-ea54e850015b"
},
"meta": {
"display_price": {
"with_tax": {
"amount": 0,
"currency": "",
"formatted": "0"
},
"without_tax": {
"amount": 0,
"currency": "",
"formatted": "0"
}
},
"timestamps": {
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "0001-01-01T00:00:00Z"
}
}
}
}
You can easily get a new or existing cart by providing the unique cart reference in the request.
warning
An empty cart is returned for any carts that don’t currently exist. For more information about the cart items object, see Get Cart Items.
note
We don’t handle creating cart references. You need to create your own.
curl -X GET https://api.moltin.com/v2/carts/:reference \
-H "Authorization: Bearer XXXX"
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
const reference = 'XXXX'
Moltin.Cart(reference)
.Get()
.then(cart => {
// Do something
})
const { MoltinClient } = require('@moltin/request')
const client = new MoltinClient({
client_id: 'X'
})
const reference = 'XXXX'
client
.get(`carts/${reference}`)
.then(cart => {
// Do something...
})
.catch(console.error)
You can import createCartIdentifier
from @moltin/request
to create a Cart ID.
const { MoltinClient, createCartIdentifier } = require('@moltin/request')
const client = new MoltinClient({
client_id: 'X'
})
const cartId = createCartIdentifier()
client
.get(`carts/${cartId}`)
.then(cart => {
// Do something...
})
.catch(console.error)