Editing orders using GraphQL
This guide explains how to use the GraphQL Admin API to edit an existing order. For example, you might add new items to a customer’s order or altering the quantity of line items.
Editing an order with the GraphQL Admin API follows a new pattern, starting with a begin mutation, then a series of edits, and finally a commit. The
orderEditBegin mutation creates a
CalculatedOrder object, which tracks the edits that you want to make to the order. When you are satisfied with your changes, the
orderEditCommit mutation commits the changes to the order.
You can make the following edits to an order with the Order editing API:
- Add new variant line items
- Add new custom line items
- Remove line items
- Alter line item quantities
Only unfulfilled line items can be edited. If an edit changes the total order value, then a balance might need to be collected from, or refunded to the customer. You can use the
orderEditCommit mutation to send an invoice to the customer that they can use to pay the outstanding balance and complete the order (similiar to completing a draft orders).
To use the GraphQL Admin API to edit orders, your app needs to request the
write_order_edits access scope for a Shopify store. For more information on requesting access scopes when your app is installed, see OAuth.
Begin order editing
orderEditBegin mutation is the first step in editing an order. Pass the order's ID to the mutation, and request the ID of the CalculatedOrder object as a return field. The CalculatedOrder object tracks the edits until you're ready to commit them to the order with the
Edit the order
Now that you have the CalculatedOrder object ID, make the following edits to the order:
Add a new variant
You can use the
orderEditAddVariant mutation to add a new product variant with a quantity of 3 to the order. Include the CalculatedOrder object ID, the variant ID and the variant quantity as the mutation's input. Request the ID of the added line items using the
addedLineItems field to verify that our variant was added correctly.
Add a custom line item
Add a custom line item to the order for gift wrapping. In the input, include the CalculatedOrder ID, line item title, quantity, and price to the
orderEditAddCustomItem field. In the response, request the added line item’s ID, title, and quantity to verify that it was added correctly.
Edit line item quantity
Adjust the line item quantity to add an additional gift wrapping service to the order using the
orderEditSetQuantity mutation. In the input, include the order
lineItemId, and the new
quantity value that you want to set. In the response, request the ID and quantity of the line items to verify that it was updated correctly.
Commit the order edits
Commit the changes to the order. The
commitEdit mutation commits the changes tracked by the CalculatedOrder object to the order. In the input, include the CalculatedOrder ID, the
notifyCustomer field set to false, and a
notifyCustomer is set to true, an email invoice with the updated order information is sent to the customer.
For additional information on editing orders: