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
Resolves to the draft order's details
create
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
Resolves to the draft order's details
delete
Delete a Draft Order
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the deletion operation details.
list
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
Resolves to the list of draft orders with pagination fields.
markPaid
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
Resolves to the created order's details.
removeLineItem
Delete a Line Item from a Draft Order.
Example
Parameters
id
stringRequireditemId
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the draft order's details
retrieve
Retrieve a Draft Order's details.
Example
Parameters
id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the draft order's details.
update
Update a Draft Order's details.
Example
Parameters
id
stringRequiredThe attributes to update in the draft order.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
Resolves to the draft order's details.
updateLineItem
Update a Line Item in a Draft 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.admin.draftOrders
.updateLineItem(draftOrderId, lineId, {
quantity: 1,
})
.then(({ draft_order }) => {
console.log(draft_order.id)
})
Parameters
id
stringRequireditemId
stringRequiredThe attributes to update in the line item.
customHeaders
Record<string, any>RequiredDefault: {}