Storefront customerAddressUpdate modifies address id

Solved
Highlighted
Shopify Partner
2 0 0

I'm trying to allow a customer to update their address through the Storefront API. The mutation works as expected but the returned id is different than the provided id. I'm able to continue referencing the address by its original id and make future mutations however the returned id changes every time. Running the exact same mutation multiple times returns different ids each time which makes me think it's possibly a hash of the data (with the updated_at field changing). This presents some difficulties in caching as there isn't a good way to update the cache by referencing the address id from the returned result.

 

Any insight into why ids are changing would be much appreciated.

 

This is the mutation:

mutation customerAddressUpdate(
    $customerAccessToken: String!
    $id: ID!
    $address: MailingAddressInput!
  ) {
    updateCustomerAddress: customerAddressUpdate(
      customerAccessToken: $customerAccessToken
      id: $id
      address: $address
    ) {
      customerAddress {
        id
      }
    }
  } 

 

0 Likes

Success.

Shopify Staff
Shopify Staff
1558 77 232

So I did some digging on this one. While the ID is changing from request to request, it's not a new object being created each time. Take this ID:

 

Z2lkOi8vc2hvcGlmeS9NYWlsaW5nQWRkcmVzcy82ODA1NTE0NDUzP21vZGVsX25hbWU9Q3VzdG9tZXJBZGRyZXNzJmN1c3RvbWVyX2FjY2Vzc190b2tlbj14TDNJVmlzenBCdHNtZlNfcWxPUHIzZE14NHh5QUNZVTVwNUxuRUhibEFZQ29zbFVPcGdacWhQOEJDSnYyVnZtLXpYeDNneHR4WjVDRnd4bWhOZHRwbmlqenFUVkgzOWFwM0U5ZmV5aHhPeElxLVRPVFdFUDIyRWR4Q3NZb2FwaHE4NGtHY28tRVJiMHc3VWxCMjRPaFl2YXEwM05xYkgtdlJBYWREdnp0Y25peVlCZkxJOGZkOTB0ZkhXQXZ3X0tNRW13YzVjYTNOdlYwa0lJSzJOSlZwVFc3T2JnSnNWNTN5cTY3SnZlal9rdTg1Q1lack1reW9Pel91akpxSXRn

When I decode the Base64 string representation, it comes out like this:

 

gid://shopify/MailingAddress/6805514453?model_name=CustomerAddress&customer_access_token=xL3IViszpBtsmfS_qlOPr3dMx4xyACYU5p5LnEHblAYCoslUOpgZqhP8BCJv2Vvm-zXx3gxtxZ5CFwxmhNdtpnijzqTVH39ap3E9feyhxOxIq-TOTWEP22EdxCsYoaphq84kGco-ERb0w7UlB24OhYvaq03NqbH-vRAadDvztcniyYBfLI8fd90tfHWAvw_KMEmwc5ca3NvV0kIIK2NJVpTW7ObgJsV53yq67Jvej_ku85CYZrMkyoOz_ujJqItg

 You'll see that the mailing address ID itself remains the same, and so does the model_name "query parameter". It's the customer_access_token parameter that appears to change from time to time, and it never seems to match the customer access token I used to make the mutation. I don't know exactly what that is, but it's possibly some kind of encoded representation of the access token, and that's the reason why the ID is changing from request to request.

 

Does that help a bit?

 

Cheers.

0 Likes
Shopify Partner
2 0 0

Thanks Alex! That does help a lot. I got around the issue I was having with some middleware but decoding the response and pulling out the id would've worked as well.

0 Likes