How to fetch customer data from cart webhook (carts/create)

Hi everyone,

I’m running into an issue while working with the carts/create webhook.

Here’s my setup:

  • I’m listening to the carts/create webhook, which gives me a cart.id and a cart.token.

  • From there, I want to fetch the cart details along with customer data (email, id, etc.).

  • The problem: the webhook payload doesn’t include the key, and when I try to fetch the cart info server-side, I can’t get the customer details.

If I fetch /cart.js client-side in the storefront, I can see the key and then use it to access more details, but this isn’t feasible for my use case since my code runs on the server (in my app).

What I’ve tried / explored:

  • Admin API: Doesn’t seem to expose carts (only checkouts/orders), so no customer data here.

  • Storefront API: I can query a cart using cartId and token, but I still can’t access customer data unless the cart was created with a buyerIdentity.customerAccessToken.

  • I want to be able to fetch customer info for a cart as soon as it’s created, ideally from the webhook or via an API call.

Questions:

  1. Is there any way to get the cart key (or equivalent) on the server when handling the webhook?

  2. Can customer details be fetched reliably at the cart stage, or is it only possible at checkout/order?

  3. Is the recommended approach to ensure carts are created with a buyerIdentity.customerAccessToken in the first place?

Any guidance would be appreciated :folded_hands:

Thanks!

Hey @Vipul_Pandey :waving_hand: Thanks for reaching out.

At the moment, the cart “key” isn’t exposed in the carts/create webhook or the Admin API (which doesn’t expose carts at all), and without that key the Storefront API will redact private buyer fields like buyerIdentity email/customer as you’ve noticed there.

In Shopify, a cart’s full ID is token?key=secret; and to access buyer info server-side you do need to capture that full ID either by creating the cart on your server via the Storefront API (cartCreate returns id+key) or by having your storefront securely POST the cart.id to your backend when it’s created (through the AJAX API for example).

Customer details at the cart stage are only available if you query with the full id+key and the cart’s buyerIdentity has been set. Guests can have an email, but a Customer ID appears only when a buyerIdentity.customerAccessToken is attached. If you need reliable customer association at cart time, the recommended approach is to create or immediately update the cart with a buyerIdentity.customerAccessToken. Otherwise, the best way to grab this info is later via the checkouts/create or orders webhooks. You would also need to make sure your app is set up to have access to protected customer data (PCD):

Hope this helps, let me know if I can clarify anything on my end here!