import Medusa from "@medusajs/js-sdk"
let MEDUSA_BACKEND_URL = "http://localhost:9000"
if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
}
export const sdk = new Medusa({
baseUrl: MEDUSA_BACKEND_URL,
debug: process.env.NODE_ENV === "development",
publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
})
sdk.store.cart.createLineItem("cart_123", {
variant_id: "variant_123",
quantity: 1
})
.then(({ cart }) => {
console.log(cart)
})Add a product variant as a line item in the cart.
import Medusa from "@medusajs/js-sdk"
let MEDUSA_BACKEND_URL = "http://localhost:9000"
if (process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL) {
MEDUSA_BACKEND_URL = process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL
}
export const sdk = new Medusa({
baseUrl: MEDUSA_BACKEND_URL,
debug: process.env.NODE_ENV === "development",
publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
})
sdk.store.cart.createLineItem("cart_123", {
variant_id: "variant_123",
quantity: 1
})
.then(({ cart }) => {
console.log(cart)
})Publishable API Key created in the Medusa Admin.
The locale in BCP 47 format to retrieve localized content.
"en-US"
The cart's ID.
Comma-separated fields that should be included in the returned data. if a field is prefixed with + it will be added to the default fields, using - will remove it from the default fields. without prefix it will replace the entire default fields.
The locale in BCP 47 format to retrieve localized content.
"en-US"
The details of the line item to add.
The ID of the product variant to add as a line item.
The item's quantity.
The item's metadata, can hold custom key-value pairs.
Pass additional custom data to the API route. This data is passed to the underlying workflow under the additional_data parameter.
OK
The cart's details.
The cart's details.
Show child attributes