GraphQL Admin API: Edit an Order's LineItem Note Attributes

I have orders that I need to allow editting of the note attributes for an individual line item. The product has custom engravings and often need to be edited after the order has been created. I’ve attempted using “beginEdit”, “orderEditUpdate” “commitEdit” sequence but it reports: OrderEditUpdateInput isn’t a defined input type (on $input

Here is the PHP code I am using:

$data['query'] = 'mutation beginEdit{
		 orderEditBegin(id: "gid://shopify/Order/'.$fullOrderID.'"){
		    calculatedOrder{
		      id
		    }
		  }
		}';
$result = shopify_graphql_call($access_token, $shopifyShop, json_encode($data));
$calculatedOrderID = $draftResponse["data"]["orderEditBegin"]["calculatedOrder"]["id"];        

$gqlLineItems = array();
$newLine = array('id' => "gid://shopify/OrderLineItem/".$shopifyOrderLineItemID, 
"customAttributes"] => $properties);
array_push($gqlLineItems, $newLine);

$data['query'] = 'mutation OrderEditUpdate($id: ID!, $input: OrderEditUpdateInput!) { orderEditUpdate(id: $id, input: $input) { calculatedOrder { id } userErrors { field message } } }';
$data['variables'] = array(
    "id" => $calculatedOrderID,
    "input" => [
        "lineItems" => $gqlLineItems
    ]
  );
$result = shopify_graphql_call($access_token, $shopifyShop, json_encode($data));

I could not find a specific LineItem update for orderEdit. It seems that this should be possible since it doesn’t affect the cost of the order.

I haven’t worked with this specific API recently but from the documentation and your example: to edit an order’s LineItem note attributes using the GraphQL Admin API in Shopify, you should follow a specific sequence of steps. First, use the orderEditBegin mutation to begin editing the order. This mutation creates a CalculatedOrder object, which tracks the edits you want to make. Then, you can use various mutations such as orderEditAddVariant, orderEditAddLineItemDiscount, or orderEditSetQuantity to make edits to the order. Once you’re satisfied with the changes, commit them with the orderEditCommit mutation.

// Begin Order Editing
$data['query'] = <<

This example uses heredoc syntax for the GraphQL queries, which can improve readability. Ensure that $properties and other variables are correctly defined and structured as per Shopify's GraphQL schema.
1 Like

This answer is not relevant. You quoted directly from the documentation and then you re-posted my code which is returning an error. My question specifically is about editing an EXISTING lineitem’s note attributes.

Wasn’t documentation, but ok… Bye!

Hey @MuskokaGeek ,

Our documentation here is going to be the best resource for order editing: https://shopify.dev/docs/apps/fulfillment/order-management-apps/order-editing#step-2-edit-the-order . This matches the available order edits that you can make in the admin as well. Currently, editing line item note attributes is not a supported order edit.

One alternative could be to store these details in order.metafields or order.customAttributes fields instead of the line item. That way they can easily be changed using the orderUpdate mutation.

Hope that helps give some more clarity on the limitations of order editing and a path to alternative ways to achieve this.

  • Kyle G.
1 Like

Thanks for the reply. I suspected the correct answer was "Currently, editing line item note attributes is not a supported order edit. " but I was hopeful I’d missed something because it seems like such an oversight that there is no way to accomplish this.

Unfortunately, the store requires engravings on individual products, so the attributes must be attached to a line item and order.metafields or order.customAttributes are associated with the entire order. Note, that this can be done with Draft Orders. I update the lineItem using the DraftOrderUpdate call. But I also need to allow this for full orders. It looks like I’ll have to provide a less elegant solution for this case.

By associating a metaobject with a line item ID and storing the required engraving data, you could effectively link custom data to individual line items.

  1. Storing Data: When an order is created or updated, create a metaobject for each line item that requires engraving. Store the engraving details in the metaobject, linked to the line item ID.

  2. Retrieving Data: When you need to access or edit the engraving details, query the metaobjects using the associated line item ID.

  3. Updating Data: To update the engraving details, modify the relevant metaobject.

    https://shopify.dev/docs/apps/custom-data/metaobjects

Using a metaobject in this way isnt really the best methodology for two reasons. First - there is a maximum limit of metaobjects allowed in an account, so you will rapidly run out of these. Second, the metaobject is tied to the line item indirectly, meaning you cannot see or manage this information from within the out of the box order admin. While it is true that you could still use a metaobject in this way, it seems that Shopify should provide the ability to update the line item properties, since it provides the ability to remove them after the order was placed, just not add/edit.