New Shopify Certification now available: Liquid Storefronts for Theme Developers

Finding an admin cart object knowing Storefront cart id

abaturytski
Visitor
1 0 0

We have a webhook listening for `carts/create` and `carts/update` events, which come with `id` and `token` fields; we store these carts locally. Our web app uses StoreFront API for creating carts, which come back with global ids that look like this: `

gid://shopify/Cart/c1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`. I am looking for a way of finding a cart we receive from webhooks knowing the global ID of the cart we created with StoreFront API. Is this doable?

 
Thanks!
 
PS. Trying to use the `xxx...` part of the Gid produced no results, with or without the `c-` prefix.

`

Replies 2 (2)
SBD_
Shopify Staff
Shopify Staff
1671 235 344

Hey @abaturytski 

 

You're on the right path - you can use the token to create a global ID. Keep in mind liquid carts and SFAPI carts aren't interoperable right now, but should be very soon. Let me know if I'm misunderstanding your query.

 

E.g. Webhook: 

"token": "c1-c6872150bf4341c375fac549298124b5"


SFAPI Cart ID:

 

gid://shopify/Cart/c1-c6872150bf4341c375fac549298124b5

 

 

Scott | Developer Advocate @ Shopify 

polarbearjoy
Shopify Partner
3 0 0

Hi SBD_,

 

What about these formats: 

  •  gid://shopify/Cart/Z2NwLXVzLWNlbnRyYWwxOjAxSDFWUkpFN05aWU1BWjJEMDJRU1dISzc5
  •  gid://shopify/Cart/c1-cbdb4c4178dafdb65ad2fb3

I have both formats come through webhooks and I am able to work with the cart object when the id/token is in the format: c1-cbdb4c4178dafdb65ad2fb3. However when the c1- is not in the id/token I am not able to use the Storefront API because a NULL is returned for the cart object.

 

I am testing on multiple environments: a partners development site, a shopify plus development site and a shopify plus production site.  The partners development site and a shopify plus production site return a cart id/token with the prefix c1- where as the shopify plus development site does not have the c1- prefex. 

 

Thoughts?