Update existing order line_item SKU

Update existing order line_item SKU

Alaxandros
Shopify Partner
19 0 9

Hi!

 

My client has a store where the product variants have just been updated with SKUs, where before that field was blank. There are about 1,00,000 old orders on that store where when you look at the order and that order's line_items, you'll see the "sku" property is blank. I'd like to update all these old order line_items to display the current skus for these variants.

 

I'm fine to run a single long job which updates every order's line_items, but not sure if either REST or GraphQL allows this. Any ideas?

Replies 3 (3)

ShopifyDevSup
Shopify Staff
1453 238 508

Hey @Alaxandros , this is a great question and observation. 

 

Currently, there isn't a mutation available to update the line item sku. This document here explains the current available options for order editing. https://shopify.dev/docs/apps/fulfillment/order-management-apps/order-editing 

 

As a workaround though, if you use the lineItems.variant.sku field instead of the lineitems.sku field, that will return the updated skus that you've added. So the new sku does exist in the order data, they just won't appear in the admin on the order. 

 



If that workaround doesn't help, can you share a little more context on why you're needing to backfill the line_item.sku on past orders? I'd like to pass that on to our product teams to consider for future updates. 

 

Kind Regards, 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Alaxandros
Shopify Partner
19 0 9

Got it, thanks for the feedback. I can main use a static mapping, locally maintained of variant IDs to SKUs. The reason I want to backfill the SKU into the line item is because I'll use the API or a 3rd party app to export some order data from Shopify, and then use similar methods to export data from other ERP systems/shipping systems, then to match up the products between these disparate systems, I have to have a mapping database or two or three. But using a uniform SKU across all systems makes things more manageable, easier to link.

 

My client has a use case where they don't know the SKU of an item when they create it in Shopify, they only know it later after they also create it in their ERP system. In one case it took a while to get that SKU back into Shopify and hundreds of thousands of orders now have no SKU, which, again is fine and can be managed with a database, was just curious if I could backfill the data for future API calls.

 

Also- I almost solely use the Admin REST API. A common use case is I want to get every order in a store (around 1 million), and selectively print/manipulate data. Would you recommend switching to GraphQL in general? Would it handle this use case (get all 1 million orders and selectively print data) as well as REST?

ShopifyDevSup
Shopify Staff
1453 238 508

Hello. Thanks for sharing that feedback, I have passed that on to the product teams! 

 

Graphql is our technology of choice for building API's and for many objects it does provide more functionality over REST (for example, b2b is only available through Graphql, and upcoming changes to the product api's). It's definitely recommended to start using it when it works. 

 

In many cases it can also make your queries more efficient as you only need to request the information you need, so you won't need to filter out the unnecessary information. For example, with the order queries I mentioned above, you can just use the variant sku field to backfill in those missing fields. 

 

For large queries with GraphQL you can also use bulk operations to get the data you need. https://shopify.dev/docs/api/usage/bulk-operations/queries 

Instead of manually paginating results and managing a client-side throttle, you can instead run a bulk query operation. Shopify’s infrastructure does the hard work of executing your query, and then provides you with a URL where you can download all of the data.

Hope that helps! 

 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog