Edit an existing order with Admin API

Apps can edit any order created by a Shopify channel (for example, POS, online store, or draft orders) or any orders the app created through the API.

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 alter the quantity of line items.

How it works

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.

Refer to the GraphQL Admin API reference for more information on order editing mutations and objects.

Types of edits to an order

You can make the following edits to an order:

  • 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 draft orders).

Access scopes

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

The 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 orderEditCommit mutation.

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 discount to the variant

The orderEditAddLineItemDiscount mutation adds a fixed amount or percentage discount to the line item. Include the CalculatedOrder object ID, the line item ID and the OrderEditAppliedDiscountInput inputs as the mutation's input.

Remove a discount from a variant

The orderEditRemoveLineItemDiscount mutation removes a fixed amount or percentage discount from the line item. Include the CalculatedOrder object ID and the discountApplicationId as the mutation's input.

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.