GraphQL - Editing an Orders Line Items

Highlighted
Tourist
7 1 3

Hello, 

 

We are looking at the newer Edit Order feature using GraphQL on the 2020-01 API version.  

 

Regarding starting the process to edit an order, it is my understanding that we need to start a mutation of `orderEditBegin` and pass in the Shopify Order Id to get the Calculated Order Id.  To be clear, this is currently working as expected and I'm able to get the Calculated Order Id back to make the next call of actually editing the order. 

 

Here is the code that I'm running to get the calculated order id. 

client = ShopifyAPI::GraphQL.client

QUERY = client.parse <<-GRAPHQL
	mutation {
		orderEditBegin(id: "gid://shopify/Order/2140232974441") {
			calculatedOrder {
				id
			}
		}
	}
GRAPHQL

result = client.query(QUERY)

From here I'm just looking to simply test changing the line item quantity of an item on the returned order. At this point, I'm not sure how to get back the Calculated Line Item Id on an order and I'm not seeing any documentation on if another call is needed to get this or what the best way of getting the Calculated Line Item Id's would be? 

 

I'm looking to run something like this.

QUERY = client.parse <<-GRAPHQL
mutation {
  orderEditSetQuantity(id: "gid://shopify/CalculatedOrder/529268841", lineItemId: "gid://shopify/CalculatedLineItem/4645169856617", quantity: 2) {
    calculatedOrder {
      id
      addedLineItems(first: 5) {
        edges {
          node {
            id
            quantity
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}
GRAPHQL

result = client.query(QUERY)

To sum up my question, What is the best way to get the calculated id's for both the order and it's line items?

 

Thank you

William

0 Likes
Highlighted
Shopify Staff
Shopify Staff
495 97 88

Hey @William_Homer 

 

If you take a look at the documentation here https://shopify.dev/tutorials/edit-an-existing-order-with-admin-api you will see that the calculated id's are returned in the response. For example, if you were editing an order to add a variant you would do: 

mutation addVariantToOrder{
  orderEditAddVariant(id: "gid://shopify/CalculatedOrder/5678", variantId: "gid://shopify/ProductVariant/19523055845398", quantity: 1){
    calculatedOrder {
      id
      addedLineItems(first:5) {
        edges {
          node {
            id
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

You would have the CalculatedOrder ID from the first mutation, and then you add in the variant ID you want to add. This will generate the CalculatedLineItems ID for you, and return it in the response. 

 

If you are looking for updating the existing ones, in your into mutation you can get the lineItems such as 

mutation orderEditBegin($id: ID!) {
  orderEditBegin(id: $id) {
    calculatedOrder {
      id
      lineItems {
        edges {
          node {
            id
          }
        }
      }
    }
    userErrors {
      field
      message
    }
  }
}

You would have access to any field here: https://shopify.dev/docs/admin-api/graphql/reference/object/calculatedorder

 

 

Let me know if that is unclear! 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes