Draft Orders
Queries and Mutations listed here are used to send requests to the Admin Draft Order API Routes.
All hooks listed 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.
Mutations
useAdminCreateDraftOrder
This hook creates a Draft Order. A draft order is not transformed into an order until payment is captured.
Example
import React from "react"
import { useAdminCreateDraftOrder } from "medusa-react"
type DraftOrderData = {
email: string
region_id: string
items: {
quantity: number,
variant_id: string
}[]
shipping_methods: {
option_id: string
price: number
}[]
}
const CreateDraftOrder = () => {
const createDraftOrder = useAdminCreateDraftOrder()
// ...
const handleCreate = (data: DraftOrderData) => {
createDraftOrder.mutate(data, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.id)
}
})
}
// ...
}
export default CreateDraftOrder
Mutation Function Parameters
The details of the draft order to create.
Mutation Function Returned Data
The list of draft orders.
useAdminUpdateDraftOrder
This hook updates a Draft Order's details.
Example
import React from "react"
import { useAdminUpdateDraftOrder } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const updateDraftOrder = useAdminUpdateDraftOrder(
draftOrderId
)
// ...
const handleUpdate = (email: string) => {
updateDraftOrder.mutate({
email,
}, {
onSuccess: ({ draft_order }) => {
console.log(draft_order.id)
}
})
}
// ...
}
export default DraftOrder
Hook Parameters
id
stringRequiredMutation Function Parameters
The details of the draft order to update.
Mutation Function Returned Data
The list of draft orders.
useAdminDeleteDraftOrder
This hook deletes a Draft Order.
Example
import React from "react"
import { useAdminDeleteDraftOrder } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const deleteDraftOrder = useAdminDeleteDraftOrder(
draftOrderId
)
// ...
const handleDelete = () => {
deleteDraftOrder.mutate(void 0, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}
// ...
}
export default DraftOrder
Hook Parameters
id
stringRequiredMutation Function Returned Data
The response returned for a
DELETE
request.
DELETE
request.useAdminDraftOrderRegisterPayment
This hook 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 React from "react"
import { useAdminDraftOrderRegisterPayment } from "medusa-react"
type Props = {
draftOrderId: string
}
const DraftOrder = ({ draftOrderId }: Props) => {
const registerPayment = useAdminDraftOrderRegisterPayment(
draftOrderId
)
// ...
const handlePayment = () => {
registerPayment.mutate(void 0, {
onSuccess: ({ order }) => {
console.log(order.id)
}
})
}
// ...
}
export default DraftOrder
Hook Parameters
id
stringRequiredMutation Function Returned Data
AdminPostDraftOrdersDraftOrderRegisterPaymentRes
AdminPostDraftOrdersDraftOrderRegisterPaymentResRequiredThe order's details.
AdminPostDraftOrdersDraftOrderRegisterPaymentRes
AdminPostDraftOrdersDraftOrderRegisterPaymentResRequireduseAdminDraftOrderAddLineItem
This hook creates a Line Item in the Draft Order.