AdminDraftOrdersResource
This class is used to send requests to Admin Draft Order API Routes. All its method
are available in the JS Client under the medusa.admin.draftOrders
property.
All methods in this class require user authentication.
A draft order is an order created manually by the admin. It allows admins to create orders without direct involvement from the customer.
Related Guide: How to manage draft orders.
Methods
addLineItem
Create a Line Item in the Draft Order.
Example
Parameters
id
stringRequiredThe line item to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>RequiredResolves to the draft order's details
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>Requiredcreate
Create a Draft Order. A draft order is not transformed into an order until payment is captured.
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.admin.draftOrders.create({
email: "user@example.com",
region_id,
items: [
{
quantity: 1
}
],
shipping_methods: [
{
option_id
}
],
})
.then(({ draft_order }) => {
console.log(draft_order.id);
})
Parameters
The draft order to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>RequiredResolves to the draft order's details
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>Requireddelete
Delete a Draft Order
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<DeleteResponse>RequiredResolves to the deletion operation details.
ResponsePromise
ResponsePromise<DeleteResponse>Requiredlist
Retrieve an list of Draft Orders. The draft orders can be filtered by parameters such as query
. The draft orders can also paginated.
Example
To list draft orders:
By default, only the first 50
records are retrieved. You can control pagination by specifying the limit
and offset
properties:
Parameters
Filters and pagination configurations to apply on the retrieved draft orders.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminDraftOrdersListRes>RequiredResolves to the list of draft orders with pagination fields.
ResponsePromise
ResponsePromise<AdminDraftOrdersListRes>RequiredmarkPaid
Capture the draft order's payment. This will also set the draft order's status to completed
and create an order from the draft order. The payment is captured through Medusa's system payment,
which is manual payment that isn't integrated with any third-party payment provider. It is assumed that the payment capturing is handled manually by the admin.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminPostDraftOrdersDraftOrderRegisterPaymentRes>RequiredResolves to the created order's details.
ResponsePromise
ResponsePromise<AdminPostDraftOrdersDraftOrderRegisterPaymentRes>RequiredremoveLineItem
Delete a Line Item from a Draft Order.
Example
Parameters
id
stringRequireditemId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>RequiredResolves to the draft order's details
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>Requiredretrieve
Retrieve a Draft Order's details.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>RequiredResolves to the draft order's details.
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>Requiredupdate
Update a Draft Order's details.
Example
Parameters
id
stringRequiredThe attributes to update in the draft order.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>RequiredResolves to the draft order's details.
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>RequiredupdateLineItem
Update a Line Item in a Draft Order.
Example
Parameters
id
stringRequireditemId
stringRequiredThe attributes to update in the line item.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>RequiredResolves to the draft order's details.
ResponsePromise
ResponsePromise<AdminDraftOrdersRes>Required