Edit existing orders
Apps can edit orders that a Shopify channel creates, such as Shopify Point of Sale (POS), Online Store, or draft orders, or orders that the app creates through the GraphQL Admin API. For example, an app might add new items to a customer’s order or alter the quantity of line items.
This guide shows how to use the GraphQL Admin API to edit an existing order.
Requirements
Anchor link to section titled "Requirements"- Your app can makeauthenticated requeststo the GraphQL Admin API.
Your app has the
write_order_edits
access scope.You've met Shopify'sprotected customer data requirements.
You're editing an order that was placed in your store currency.
Your store currency is the currency that's used in your Shopify admin to price products and display reports. You can only edit orders placed in your store currency, regardless of whether you sell in multiple currencies.
You're editing an order that was placed after January 1, 2019. You can't edit archived orders or orders placed before January 1st, 2019.
Step 1: Begin order editing
Anchor link to section titled "Step 1: Begin order editing"TheorderEditBegin
mutation is the first step in editing an order. TheorderEditBegin
mutation creates aCalculatedOrder
object, which tracks the edits that you want to make to the order.
The following example shows how to pass the order's ID to theorderEditBegin
mutation and request the ID of theCalculatedOrder
object as a return field:
Step 2: Edit the order
Anchor link to section titled "Step 2: Edit the order"After you have theCalculatedOrder
object ID, you can make the following types of edits to the order:
- Add a new variant
- Add a discount to the variant
- Remove a discount from a variant
- Add a custom line item
- Edit line item quantity
Add a new variant
Anchor link to section titled "Add a new variant"Add a new product variant to an order with theorderEditAddVariant
mutation.
The following example adds a new product variant with a quantity of three to the order:
In the mutation's input, include theCalculatedOrder
object ID, the variant ID and the variant quantity. Request the ID of the added line items using theaddedLineItems
field to verify that our variant was added correctly.
Add a discount to the variant
Anchor link to section titled "Add a discount to the variant"Add a fixed amount or percentage discount to a line item with theorderEditAddLineItemDiscount
mutation.
In the mutation's input, include theCalculatedOrder
object ID, the line item ID, and theOrderEditAppliedDiscountInput
inputs.
Remove a discount from a variant
Anchor link to section titled "Remove a discount from a variant"Remove a fixed amount or percentage discount from a line item with theorderEditRemoveLineItemDiscount
mutation.
In the mutation's input, include theCalculatedOrder
object ID and thediscountApplicationId
.
Add a custom line item
Anchor link to section titled "Add a custom line item"Add a custom line item to an order with theorderEditAddCustomItem
mutation.
The following example adds a custom line item to the order for gift wrapping.
In the mutation's input, include theCalculatedOrder
ID, line item title, quantity, and price in theorderEditAddCustomItem
field. In the response, request the added line item’s ID, title, and quantity to verify that the custom line item was added correctly.
Edit line item quantity
Anchor link to section titled "Edit line item quantity"You can use theorderEditSetQuantity
突变调整行项目数量增加n additional gift wrapping service to the order.
In the mutation's input, include the orderid
,lineItemId
, and the newquantity
value that you want to set. In the response, request the ID and quantity of the line items to verify that the line item quantity was updated correctly.
第三步:提交订货单r edits
Anchor link to section titled "Step 3: Commit the order edits"When you're satisfied with your changes, you can commit them to the order with theorderEditCommit
mutation. TheorderEditCommit
mutation commits the changes tracked by theCalculatedOrder
object to the order.
In the mutation's input, include theCalculatedOrder
object ID, thestaffNote
field, and thenotifyCustomer
field set tofalse
. IfnotifyCustomer
is set totrue
, then an email invoice with the updated order information is sent to the customer.
Step 4: Subscribe to a webhook
Anchor link to section titled "Step 4: Subscribe to a webhook"To be notified when an order is edited, subscribe your app theorders/updated
webhook. The webhook is triggered whenever an order edit is completed.
To learn how to set up and consume webhooks, refer toWebhooks configuration overview.
Next steps
Anchor link to section titled "Next steps"- Consult themerchant documentationto learn about editing orders in the Shopify admin.
- Learn how tocreate test orders and transactionsto validate your app's behavior.
- Explore examples for querying orders, includingretrieving sales data from an order, using the GraphQL Admin API.