Product ID in Admin API vs. Product ID in GraphQL

NexusMedia
New Member
2 0 1

Hello,

We're currently working on Android app based on Mobile Buy SDK v3 and find out that Product IDs (and IDs for other entities also) are not the same as IDs in Admin API (and Shopify Admin panel, theme templates, etc). I.e. it looks like the same product has two different product ids. So, the question is, is there any way to get product by "normal" product id using GraphQL, or we are limited to use handles only?

Thank you for your suggestions.

Steve_F
Shopify Partner
4 0 1

Also need this functionality, help with this would be appreciated.

0 Likes
Vahe_Evoyan
New Member
2 0 4

Hey there, seems I found the relation between these. You base64 decode the GraphQL ID and get something like gid://shopify/ProductVariant/1111111111. Only thing left is to get the last part of the URI.

cdep
New Member
2 0 0

Very helpful. If anyone wants a quick implementation:

 

 

import atob from 'atob'

export const getShopifyIdFromBase64 = base64Id => {
  const decoded = atob(base64Id)
  const shopifyId = decoded.split("/").pop()
  return parseInt(shopifyId)
}

 

 

0 Likes
faizan_haidar
Tourist
4 0 0

Product also has an id that can be get by

productModel.get("id").toString();
0 Likes
faizan_haidar
Tourist
4 0 0

You can also get product by

productModel.get("id").toString()

It will give you a response like this   {id=Z2lkOi8vc2hvcGlme................1MTU2MzE1NTg4MTY=}

0 Likes