What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

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

Jalvarez2000
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!

Replies 5 (5)

Jalvarez2000
Tourist
6 0 1

Not applicable

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

Jalvarez2000
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);
Not applicable

Hi @Jalvarez2000 ,

 

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

 

Regards,

 

Sam

vix
Shopify Staff
541 103 123

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.

To learn more visit the Shopify Help Center or the Community Blog.