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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

cartBuyerIdentityUpdate mutation problem

cartBuyerIdentityUpdate mutation problem

Devtest1
Visitor
1 0 0

Hey!
I'm trying to implement cart functionality currently, I've got a problem with singing valid customers to the newly created cart.
By this, I mean that I'm unable to add customerAccessToken to createCart mutation directly or cartBuyerIdentityUpdate mutation. With these two approaches, I'm getting the same error message:

 

{
  "data": {
    "cartBuyerIdentityUpdate": {
      "cart": null,
      "userErrors": [
        {
          "code": "INVALID",
          "field": [
            "buyerIdentity",
            "customerAccessToken"
          ],
          "message": "Customer is invalid"
        }
      ]
    }
  }
}

 

 My mutation for update looks like that:

 

mutation cartBuyerIdentityUpdate($cartId: ID!, $buyerIdentity: CartBuyerIdentityInput!) {
  cartBuyerIdentityUpdate(cartId: $cartId, buyerIdentity: $buyerIdentity) {
    cart {
      id
      buyerIdentity {
        email
        phone
        countryCode
        customer {
          email
        }
      }
    }
    userErrors {
      code
      field
      message
    }
  }
}

variables to mutation: 
{
  "cartId": "Z2lkOi8vc2hvcGlmeS9DYXJ0L2FkOGRhMDNhMmQ5NzQ1N2YxYjJmZjhjY2QzZTgwYzY2",
  "buyerIdentity": {
    "customerAccessToken":"b95d5f29ed2250f13c76dc6fea711ee1"
   }
}

 

 both customer account and cart were created directly before calling this mutation.

All other fields passed with buyerIdentity work fine besides token.
Thanks for any help!

Replies 2 (2)

Luke_K
Shopify Staff
402 66 103

Hey @Devtest1 

Thanks for raising this! So, in short, applying the customer token seemed to work ok for me - I followed this flow calling the api/unstable/graphql.json Storefront API endpoint.

1. Created customer and used customerAccessTokenCreate to create customers access token

2. Called createCart and received my Cart ID

3. I copy pasted the mutation from your screenshot for CartBuyerIdentityUpdate and passed my cartId and customerAccessToken

4. I was able to successfully apply the CartBuyerIdentityUpdate mutation - I didn't receive the "customer is invalid" message myself.

I managed to received successful response when calling createCart too with this input :

{
  "cartInput": {
  "buyerIdentity": {
		"customerAccessToken": "customer_access_token"
	}
 }
}

The "INVALID" error(docs) points to an invalid input CustomerUserError  - I would check that the customer inputs are valid,  the customer Access Token is a valid one (not expired) and also that the correct access token is applied. Hope that helps!

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
samir-growwx
Shopify Partner
6 0 3

Hey Luke_K, I am trying this mutation https://shopify.dev/docs/custom-storefronts/building-with-the-storefront-api/cart/manage#step-4-upda... to update the customer, in the response, it shows that customer entity /buyer entity has been updated, but if I try getting cart details it shows buyerEntity null  

Could you please help me with this, I have attached the ss

Screenshot 2023-03-31 at 9.09.00 PM.png

Screenshot 2023-03-31 at 9.10.59 PM.png