Wha is the difference between customer Id in store front and customer Id in Admin API

Highlighted
Tourist
6 0 1

I need to know how I can get the customer Id that Admin API provides you directly from Customer Id that FrontEnd API gives you back

 

For example, I m getting this customer Id in Admin API: 3174076055691

 

And inf frontend API this is something like: Z2lkOi8vc2hvcGlmeS9DdXN0b21lci8zMTc0MDc2MDU1Njkx

 

Thanks!

0 Likes
Highlighted
Highlighted
Shopify Partner
199 13 36

Hi @Jalvarez2000 ,

 

What do you mean by frontend API? Can you be more specific. When a customer is signed in the customer ID can be accessed through Liquid syntax like so:

 

{{customer.id}}

If you want to access it else where in your application:

 

  	<script>
  		var customer_id = {{customer.id}}
                this.yournamespace = customer_id
  	</script>

Is there a specific reason you need to fetch the customer ID? If you had the customer ID then yes you can query Admin API and retrieve a single customer record.

 

Regards,

 

Sam

Shopify Themes and Custom Apps | hello@achieveapplabs.com
0 Likes
Highlighted
Tourist
6 0 1

I mean Storefront API.

 

The issue I found is I wanted to match storefrontAPI  customer Id and Admin API customer Id, as they were different. 

 

I found the way here (C# code):

 

byte[] data = System.Convert.FromBase64String(storefrontIfo.customer.id);
String gid = System.Text.ASCIIEncoding.ASCII.GetString(data);
UserInfo.shopifyId = gid.Substring(gid.LastIndexOf("/") + 1);
0 Likes
Highlighted
Shopify Partner
199 13 36

Hi @Jalvarez2000 ,

 

Storefront API uses GraphQL where Admin API uses REST. Hence why the IDs appear different. 

 

Regards,

 

Sam

Shopify Themes and Custom Apps | hello@achieveapplabs.com
0 Likes
Highlighted
Shopify Staff
Shopify Staff
390 72 54

Hey Everyone! 

 

Just chiming in here since this is a highly viewed thread. The IDs between the Storefront API and the Admin API do differ. As you've discovered, you can base64 encode the GID from the Admin API to get the Storefront API. This is due to being a public unauthenticated API - the Admin API can be accessed in both GraphQL and REST.

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes