Skip to main content

Create Cart

Creates a cart using a 10-digit catalogId.

Save this example as 04-create-cart.mjs.

import { printJson, readConfig, requireStoreId, thyrisRequest } from "./thyris-client.mjs"

const config = readConfig()
const storeId = requireStoreId(config.storeId)
const catalogId = process.env.THYRIS_CATALOG_ID || process.argv[2]

if (!catalogId) {
throw new Error("Pass a catalogId as the first argument or set THYRIS_CATALOG_ID")
}

const result = await thyrisRequest(config, "/api/v1/catalog/carts", {
method: "POST",
body: JSON.stringify({
storeId,
items: [
{
catalogId,
quantity: Number(process.env.THYRIS_CART_QUANTITY || 1),
},
],
otherDetails: {
channel: "sample-script",
},
}),
})

printJson(result)