Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

OrdersResource

This class is used to send requests to Store Order API Routes. All its method are available in the JS Client under the medusa.orders property.

Orders are purchases made by customers, typically through a storefront. Orders are placed and created using CartsResource. The methods in this class allow retrieving and claiming orders.

Related Guide: How to retrieve order details in a storefront.

Methods​

retrieve​

Retrieve an Order's details.

Example​

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.orders.retrieve(orderId)
.then(({ order }) => {
console.log(order.id);
})

Parameters​

idstringRequired
The order's ID.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<StoreOrdersRes>Required
Resolves to the details of the order.

retrieveByCartId​

Retrieve an order's details by the ID of the cart that was used to create the order.

Example​

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.orders.retrieveByCartId(cartId)
.then(({ order }) => {
console.log(order.id);
})

Parameters​

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

Default: {}

Returns​

ResponsePromiseResponsePromise<StoreOrdersRes>Required
Resolves to the details of the order.

lookupOrder​

Look up an order using filters. If the filters don't narrow down the results to a single order, a 404 response is returned with no orders.

Example​

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
medusa.orders.lookupOrder({
display_id: 1,
email: "user@example.com"
})
.then(({ order }) => {
console.log(order.id);
})

Parameters​

payloadStoreGetOrdersParamsRequired
Filters used to retrieve the order.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<StoreOrdersRes>Required
Resolves to the details of the order.

requestCustomerOrders​

Allow the logged-in customer to claim ownership of one or more orders. This generates a token that can be used later on to verify the claim using the confirmRequest method. This also emits the event order-update-token.created. So, if you have a notification provider installed that handles this event and sends the customer a notification, such as an email, the customer should receive instructions on how to finalize their claim ownership.

Example​

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.orders.requestCustomerOrders({
order_ids,
})
.then(() => {
// successful
})
.catch(() => {
// an error occurred
})

Parameters​

The orders to claim.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromiseRequired
Resolves when the request is created successfully.

confirmRequest​

Verify the claim order token provided to the customer when they request ownership of an order.

Example​

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.orders.confirmRequest(
token,
)
.then(() => {
// successful
})
.catch(() => {
// an error occurred
})

Parameters​

The claim order to verify.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromiseRequired
Resolves when the claim order is verified successfully.
Was this section helpful?