Skip to main content
Skip to main content

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

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.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminDraftOrdersRes>Required
Resolves to the draft order's details

addLineItem

Create a Line Item in the 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.addLineItem(draftOrderId, {
quantity: 1
})
.then(({ draft_order }) => {
console.log(draft_order.id);
})

Parameters

idstringRequired
The ID of the draft order.
The line item to create.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminDraftOrdersRes>Required
Resolves to the draft order's details

delete

Delete 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.delete(draftOrderId)
.then(({ id, object, deleted }) => {
console.log(id);
})

Parameters

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

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation details.

removeLineItem

Delete a Line Item from 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.removeLineItem(draftOrderId, itemId)
.then(({ draft_order }) => {
console.log(draft_order.id);
})

Parameters

idstringRequired
The ID of the draft order that the line item belongs to.
itemIdstringRequired
The ID of the line item to delete from the draft order.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminDraftOrdersRes>Required
Resolves to the draft order's details

retrieve

Retrieve a Draft Order's details.

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.retrieve(draftOrderId)
.then(({ draft_order }) => {
console.log(draft_order.id);
})

Parameters

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

Default: {}

Returns

ResponsePromiseResponsePromise<AdminDraftOrdersRes>Required
Resolves to the draft order's 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:

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.list()
.then(({ draft_orders, limit, offset, count }) => {
console.log(draft_orders.length);
})

By default, only the first 50 records are retrieved. You can control pagination by specifying the limit and offset properties:

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.list({
limit,
offset
})
.then(({ draft_orders, limit, offset, count }) => {
console.log(draft_orders.length);
})

Parameters

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

Default: {}

Filters and pagination configurations to apply on the retrieved draft orders.

Returns

ResponsePromiseResponsePromise<AdminDraftOrdersListRes>Required
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

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.markPaid(draftOrderId)
.then(({ order }) => {
console.log(order.id);
})

Parameters

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

Default: {}

Returns

ResponsePromiseResponsePromise<AdminPostDraftOrdersDraftOrderRegisterPaymentRes>Required
Resolves to the created order's details.

update

Update a Draft Order's details.

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.update(draftOrderId, {
email: "user@example.com"
})
.then(({ draft_order }) => {
console.log(draft_order.id);
})

Parameters

idstringRequired
The ID of the draft order.
The attributes to update in the draft order.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminDraftOrdersRes>Required
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

idstringRequired
The ID of the draft order that the line item belongs to.
itemIdstringRequired
The ID of the line item to update.
The attributes to update in the line item.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminDraftOrdersRes>Required
Resolves to the draft order's details.
Was this section helpful?