Product_id and Inventory_item_id

Solved
Hasimew
Tourist
6 1 1

Hello All,

 Forgive my ignorance, but i find it very frustrating that Shopify needs Inventory_item_id to be able to update inventory via the API. However, they dont make it easy to get that value. I found some docs on how to grab the Inventory_item_id, but you will need the product_id first to get that to work. 

 

Interestingly, you can only (from what I can see) get the product_id from the product's url. If there is an API call that I can make using the SKU to get the Product ID, then please educate me on it. I have clients that have over 4k SKU, the idea of going into those SKU's one by one to grab the product_id is just unrealistic at the very best. Shopify could have done a better JOB by including either the product_id and or inventory_item_id on the "Product export" feature. This would have been the simplest and most logical thing to do. 

 

I spent the last 5 days, almost 3-4 hrs searching through this, I am yet to find a possible solution that does not results to me wanting to pull my hair out. I am either just too dumb to get this process or the other guys is. 

 

To sum it up?

HOW for the love of God, can I easily get the Product_id without going through each individual product's url, or better yet, how can I easily get the inventory_item_id using the SKU without going through the product_id?

 

Thanks 

Accepted Solution (1)

Accepted Solutions
Hasimew
Tourist
6 1 1

This is an accepted solution.

Hello,

 This worked, thank you for the insight

View solution in original post

Replies 13 (13)
DeveloperRK
Shopify Partner
17 0 0

Hello 

Hasimew
Tourist
6 1 1

Hello,

 Thank you for the insight, I actually found that app after I sent the message, and these guys did an amazing job in being able to pull all the IDs'. If I was a simple personal user, this would have been great. However, I run a fulfilment company, we have lots of customers that sells on Shopify. Some with 10 SKU while others have up to 4K SK's. 

 

The app has a monthly fee, to be able to export the data into excel. Even if they do that, they would then need to load that data somehow in my system because all the inventory lives on my system which has the connection to Shopify. I am very good with excel and can do v-lookups between the data in my system and the data from these guys to match things and then load into my system. Issue is, most people out there are not that good with excel thus making it a bit challenging for them to use the app efficiently. 

 

Bottom line is, I love the app. Love what they did, my hat off for whom ever figure this out. To make it easy for my clients, I have to figure this out as well  somehow 🙂 because I now know that its not impossible. 

 

Sorry for the long reply, but thank you for the response. 

DeveloperRK
Shopify Partner
17 0 0

Hello Hasimew,

Thank you for appreciating app. Actually this is my app.

So to help you further more, I have an offer for you.

You can tell me exact format of excel which your users wants to export and use on your system.

Your users will not have to play with excel, I will provide them exact the same format which they need & they will have to just export and use it directly on your system. With this you will also save a lots of time on your side.  Further offer is we can deal with some discounts for your users on app.

If you will install it on one of your shop then inside app you will find my communication details.

I am open with ideas.

Best Regards

vix
Shopify Staff
Shopify Staff
540 103 118

Hi @Hasimew 

 

GraphQL or Rest? With either you can use the Product API and use query params to get what you want. For example: https://shopify.dev/docs/admin-api/rest/reference/products/product?api[version]=2020-04#index-2020-0...

 

GET /admin/api/2020-04/products.json?handle="your handle" 

 

Hasimew
Tourist
6 1 1

This is an accepted solution.

Hello,

 This worked, thank you for the insight

Hasimew
Tourist
6 1 1

Hello,

 I bounced that idea to my partner and it will be complicated to get my clients to go for it as it will involve much more oversight than we need. But thanks for the offer, you did a great job with your app seriously. 

 

Thanks 

Tony49
Shopify Partner
36 2 5

I am confused:  Did you figure out how to find inventory_item_id based only on the SKU?

 

Basically, I know the SKU ( I store it on my end ), so I just need to get the inventory_item_id for that SKU and then update the inventory.  My users don't need to see it, we only want to manage SKU on our end.  I read all the posts in this thread, but could not really figure out how to do it.

 

I did try the following with my SKU, IT-9284-1000-BSK-LG, and got back the results below, with a bad parameter:

curl -i -X POST https://<API_KEY>:<API_PASSWORD>@<store>.myshopify.com/admin/api/2020-04/products.json?handle="IT-9284-1000-BSK-LG"

HTTP/1.1 400 Bad Request
Date: Sat, 01 Aug 2020 00:42:06 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
... /*http stuff*/

X-Shopify-API-Terms: By accessing or using the Shopify API you agree to the Shopify API License and Terms of Use at https://www.shopify.com/legal/api-terms
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Shopify-Shop-Api-Call-Limit: 1/40
X-Shopify-API-Version: 2020-04
... /*http stuff*/

{"errors":{"product":"Required parameter missing or invalid"}}

 

Hasimew
Tourist
6 1 1

https://shopify.dev/docs/admin-api/rest/reference/products/product-variant?api[version]=2020-07

this is what we used for get individual item ID based on the sku. It can also get all products, then search each individual item id based on the sku on the local https://shopify.dev/docs/admin-api/rest/reference/products/product?api[version]=2020-07

Tony49
Shopify Partner
36 2 5

Yes, I already have a script going through all products (using producst.json ), but that is really wasteful to just look for one part, thus this whole question.

 

I don't understand how to use variants to get the item_inventory_id for a given SKU.  I don't see it in the documentation you referenced.  I have read it multiple times and every search it lets you do requires a "product_id" or "variant_id".  I only have the SKU, nothing else.  How did you do that?  I am reading between the lines, but maybe you did this:

  1. Somehow get product_id ( still not entirely sure how you did that, but separate question )
  2. Used product_id to get item_inventory_id using variants.json stuff ( your first link )

I guess my confusion is how to get the product_id if you only have the SKU?  How do you search by SKU via the API?  The example in the answer that I think was accepted said

GET /admin/api/2020-04/products.json?handle="your handle"

But I tried that, assuming "handle=<sku>" would work, and it did not.  So you must be doing something else.  I really hope you don't have to do a two step process like I assume above, but maybe you do and maybe I just need to know how to do the first step correctly.  Any help on the actual command to search for a given SKU would be much appreciated.

Tony49
Shopify Partner
36 2 5

Currently I have code that goes through all variants one by one, page by page, to find my SKU, and then I grab that inventory_item_id.  But this is hugely inefficient.  Does anyone know of a better way?  You seemed to have solved a very similar problem, so I was hoping you could point me in the right direction.

Tony49
Shopify Partner
36 2 5

Here is the complete command that works for me, in case anyone is interested:

curl -i -X POST https://myfakestore.myshopify.com/admin/api/2020-01/graphql.json -H 'Cache-Control: no-cache' -H 'Content-Type: application/graphql' -H 'X-Shopify-Access-Token: APIKEY_TOKEN' -d '{
    productVariants(first: 1, query: "sku:IT-9284-1000-BSK-LG") {
        edges
        {
            node {
                id
                sku
                legacyResourceId
                displayName
                inventoryItem {
                    id
                    legacyResourceId
                }
            }
        }
    }
}
'
Bren607
New Member
1 0 0
GET /admin/api/2020-04/products.json?handle="your handle" 

Did anyone get this working via the above method? 

I also want to get the product id from the sku.  

I have tried the following, it does not work.

GET /admin/api/2020-04/products.json?sku="1234" 

Desparately need a solution other than the graphql.json suggestion.

rasta1994
New Member
1 0 0

Hi this works fine, but it only shows the first page. Does anyone knows how to show all products. 

 

https://yourshop.myshopify.com/admin/variants.xml?fields=id,sku,inventory-item-id

 

 

Hoping for any response and idea. 

 

Thank you

 

Here is the sample response. 

 

<variants type="array">
<variant>
<id type="integer">22288836296804</id>
<sku>MT-HN100</sku>
<inventory-item-id type="integer">23120125755492</inventory-item-id>
</variant>
<variant>
<id type="integer">22288862478436</id>
<sku>ON-GSW-1DRC</sku>
<inventory-item-id type="integer">23120142762084</inventory-item-id>
</variant>
<variant>
<id type="integer">22288864215140</id>
<sku>ON-PG10-DC</sku>
<inventory-item-id type="integer">23120148889700</inventory-item-id>
</variant>
<variant>
<id type="integer">22288876666980</id>
<sku>SAN-FFG120</sku>
<inventory-item-id type="integer">23120158392420</inventory-item-id>
</variant>
<variant>
<id type="integer">22288884858980</id>
<sku>ON-SM-12CHC</sku>
<inventory-item-id type="integer">23120161308772</inventory-item-id>
</variant>
<variant>
<id type="integer">22288896000100</id>
<sku>GAT-MMT150</sku>
<inventory-item-id type="integer">23120186081380</inventory-item-id>
</variant>