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!

0 Likes
achieveapplabs
Shopify Partner
472 36 74

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

Install Approovly to create and track order approvals | We want to hear from you hello@achieveapplabs.com | Follow us on Twitter @achieveapplabs | Custom Shopify Apps achieveapplabs.com
0 Likes
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);
0 Likes
achieveapplabs
Shopify Partner
472 36 74

Hi @Jalvarez2000 ,

 

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

 

Regards,

 

Sam

Install Approovly to create and track order approvals | We want to hear from you hello@achieveapplabs.com | Follow us on Twitter @achieveapplabs | Custom Shopify Apps achieveapplabs.com
0 Likes
vix
Shopify Staff
Shopify Staff
534 105 103

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? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes