Skip to main content
Skip to main content

LineItemsResource

This class is used to send requests to Line Item API Routes part of the Store Cart API Routes. All its method are available in the JS Client under the medusa.carts.lineItems property.

Methods

create

Generates a Line Item with a given Product Variant and adds it to the Cart

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.carts.lineItems.create(cart_id, {
variant_id,
quantity: 1
})
.then(({ cart }) => {
console.log(cart.id);
})

Parameters

cart_idstringRequired
The cart's ID.
The line item to be created.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<StoreCartsRes>Required
Resolves to the associated cart's details.

delete

Delete a line item from a cart. The payment sessions will be updated and the totals will be recalculated.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.carts.lineItems.delete(cartId, lineId)
.then(({ cart }) => {
console.log(cart.id);
})

Parameters

cart_idstringRequired
The ID of the line item's cart.
line_idstringRequired
The ID of the line item to delete.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<StoreCartsRes>Required
Resolves to the associated cart's details.

update

Update a line item's data.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.carts.lineItems.update(cartId, lineId, {
quantity: 1
})
.then(({ cart }) => {
console.log(cart.id);
})

Parameters

cart_idstringRequired
The ID of the line item's cart.
line_idstringRequired
The ID of the line item to update.
The data to update in the line item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<StoreCartsRes>Required
Resolves to the associated cart's details.
Was this section helpful?