How can we get customer information for carts/update event?

We need to fetch info related to customer from the carts/update data. We can run a graphql query, but didn’t find any useful graphql query to fetch direct checkout/customer linked to cart info using only this cart data:

{
“id”: “exampleCartId”,
“token”: “exampleCartId”,
“line_items”: [
{
“id”: 704912205188288575,
“properties”: null,
“quantity”: 3,
“variant_id”: 704912205188288575,
“key”: “704912205188288575:3abdf474dce81d0025dd15b9a02ef6bf”,
“discounted_price”: “19.99”,
“discounts”: ,
“gift_card”: false,
“grams”: 200,
“line_price”: “59.97”,
“original_line_price”: “59.97”,
“original_price”: “19.99”,
“price”: “19.99”,
“product_id”: 788032119674292922,
“sku”: “example-shirt-s”,
“taxable”: true,
“title”: “Example T-Shirt - Small”,
“total_discount”: “39.98”,
“vendor”: “Acme”,
“discounted_price_set”: {
“shop_money”: {
“amount”: “19.99”,
“currency_code”: “USD”
},
“presentment_money”: {
“amount”: “19.99”,
“currency_code”: “USD”
}
},
“line_price_set”: {
“shop_money”: {
“amount”: “59.97”,
“currency_code”: “USD”
},
“presentment_money”: {
“amount”: “59.97”,
“currency_code”: “USD”
}
},
“original_line_price_set”: {
“shop_money”: {
“amount”: “59.97”,
“currency_code”: “USD”
},
“presentment_money”: {
“amount”: “59.97”,
“currency_code”: “USD”
}
},
“price_set”: {
“shop_money”: {
“amount”: “19.99”,
“currency_code”: “USD”
},
“presentment_money”: {
“amount”: “19.99”,
“currency_code”: “USD”
}
},
“total_discount_set”: {
“shop_money”: {
“amount”: “39.98”,
“currency_code”: “USD”
},
“presentment_money”: {
“amount”: “39.98”,
“currency_code”: “USD”
}
},
“parent_relationship”: null
}
],
“note”: null,
“updated_at”: “2022-01-01T00:00:00.000Z”,
“created_at”: “2022-01-01T00:00:00.000Z”
}

Hi @Jaspreet_Singh,

If you have the cart id, through the webhook, you can use the cart query on the Storefront API.

This should return the cart object on the Storefront API, and you can get the checkout and customer information via the cart.checkoutUrl and cart.buyerIdentity fields on the cart object.

but for storefront api we will need additional access and token, right? Our app is meant to be normally used by other merchants and we are not taking there storefront api access tokens

Hi @Jaspreet_Singh,

That is correct, if you are going to be accessing a Cart from a store, you do need access to that store data via the Storefront API token. The use of the token means that you have approval to access the storefront data, and is required for merchant security.

If your app is subscribing to webhooks you should have an Admin API access token already, you can use that to create Storefront API access tokens as well, with the storefrontAccessTokenCreate mutation.

Here’s some documentation with more info on Storefront API Authentication.

1 Like

Can we do it using unauth admin api? And is there a way to get a storefront api access token when a user installs our app?

@Kellan-Shopify we are not getting the any data under buyer identity even with a logged in user for this cart. Is there something else that we need to do?

```
curl -s -X POST “test1 -H “Content-Type: application/json” -H “X-Shopify-Storefront-Access-Token: <REMOVED>” -d ‘{
“query”: “{ cart(id: “gid://shopify/Cart/hWNA0AKMkVlCz7cdyHMQoQ4K”) { id buyerIdentity { email phone countryCode customer { id firstName lastName email phone } } } }”
}’
```

Hi @Jaspreet_Singh,

You are unable to do this with an unauthenticated api call, as all Admin API calls do required full authentication, and to make the Storefront API call from your custom app you need a Storefront API token retrieved from the custom app.

Alternatively if you’re creating a custom storefront and not using the Admin API, you can install the Headless or Hydrogen channels on the store and generate a Storefront API access token through there instead. But this is only for custom storefronts, if this is an app you will need to do it through the methods mentioned previously.

All discussed in the Shopify.dev documentation: Shopify API authentication

Regarding the API call that you shared, I’d like to ask you to please reach out to our support team via the Shopify Help Center, and we can help look into any specific examples further in a fully authenticated support interaction, so we can discuss specific cart details with you securely.

When reaching out through the Help Center, please make sure that you are logged into a partner or store account that has access to the app making the calls, and provide us with the following details from the API call that’s not returning the expected data:

  • The full plain text HTTP Request, including URL, Body, and Headers (no access tokens)
  • The full plain text HTTP Response, including Body and Headers

In this case you’ve provided the HTTP Request headers and Body, so please make sure to gather the HTTP Response Headers and Body before reaching out as well.


Additionally I do see that you have shared an access token in your last reply, I’ve removed it from your post for now, but please make sure that you don’t share these tokens moving forward, as they are meant to secure your app and store, and exposing them can cause a security concern with potential bad actors having access to your store unexpectedly.

Please be sure to revoke the token that you shared here, and rotate your API credentials, to remain secure moving forward, following the documentation: