GraphQL add to the Line Items of existing order

Santa
Tourist
9 0 1

Hi,

I'm not sure if this is possible, but I'd like to be able to add something into the existing line items of an order. There's some information that I'd like to be able to add to an order when we finish it that we can reference later (a custom url). I was hoping there was a way to add it as a string into the line items of an order, so it would show up as something like "url=www.customurl.com". I've found ways to add a product variant or a custom attribute, but I haven't found a way to do this. Anyone know if this is possible?

Thanks

0 Likes
HunkyBill
Shopify Expert
4488 45 485

Line items that have not been fulfilled can be edited. If they have been fulfilled you cannot edit them, for the obvious reason that they are shipped and in the books now. You could likely ALWAYS succeed by simply storing the text you want as an order attribute. That way your wish comes true. You could for example set the name to be the line item name, and the value to be the custom value you need to store. Simple. Works. All the time.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Santa
Tourist
9 0 1

Thanks for the reply

The order wouldn't be fulfilled at this point. I'm confused what graphQL mutation to use to add a string to the existing line items (I'm new to this so still learning) . I've tried orderEditAddCustomItem but there's no quantity or price.

Does adding it as an order attribute add it to the order notes? I'm using the order notes for something else already, but will definitely use that if I can't figure out another way.

Thanks again.

0 Likes
HunkyBill
Shopify Expert
4488 45 485

Regardless of the order being fulfilled, you often have to do some logical thinking. I will paint you a picture that illustrates.

Long ago, with the introduction of metafields, we could store a number or a string with a resource. So a lot of people got all giggly, and decided they could improve their lot in life with Shopify by adding a metafield to every variant a product has (like a line item an order has), and therefore allow for a richer experience. Great, until you realize the amount of API calls and overhead management you experience when rolling up and unrolling all these metafields.

So upon reflection, since you can store a String, and JSON is nothing but a String, why not store JSON at the product level, where every key is a variant ID and the value is the important rich stuff? Heck, Shopify even added a JSON metafield to make that easier. So now with one API call, you get a JSON dataset that describes ALL your products. Not 10 API calls, not 99... one.

Orders also allow this, in addition to the NOTE attribute you mention, they also have a key:value attribute store. That is all I was saying. And it comes with no restrictions on when you can use it, and you can get at it at any time. That being said, if you can alter the line item product, and alter that products properties, also a key value store, your operators in Shopify Admin would see those extra notes added, right along with the line item products.

Have fun! All this is pretty easy stuff to do!

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Santa
Tourist
9 0 1

Thank you so much for the response, I really appreciate it.

The thing I'm having trouble figuring out in the Shopify documentation is how to actually add a key:value to the line items. I can see that there is a customAttributes under the LineItem section (https://shopify.dev/docs/admin-api/graphql/reference/orders/lineitem) which seems to be what I'd want to use, but I can't see which graphQL mutation will let me add a new key:value into the line items (for an order that is already placed but not yet fulfilled). Sorry if I'm missing something obvious here.

0 Likes