Ad

Given Node For Storefront.Product With String Id, How To Get ProductId For Admin API

- 1 answer

I'm using GraphQL shopify buy-sdk for Android, and getting node for Product, by string id like:

"id" -> "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzEwMDcyMDgwOTc1"

this is node id

but to get, say, product metafields, i have to make request to Admin API

https://SHOP.myshopify.com/admin/products/{productId}/metafields.json

where {productId} is numeric id of Product, like:

6243834538

I cannot use node id in REST API request, getting 400 "Bad Request".

So the question is - how to get numeric product id for node in GraphQL?

Thanks!

Ad

Answer

You can simply do a base64 decode to the string id. By decoding (base64) the string you gave in the example I found something like this.

gid://shopify/Product/10072080975

You can trim the string to get the product id from the end and can use in the rest api of shopify admin api.

Ad
source: stackoverflow.com
Ad