Am I using the same api or what am I doing wrong here?

Solved

Am I using the same api or what am I doing wrong here?

vlgwlf
Shopify Partner
1 0 0

Hi! So I'm developing a small app and I'm trying to update a customer based off of a first call I'm making with GraphQL:

 

 

 

 

const queryString = `{
    customers(first: 10) {
      edges {
        node {
          firstName
          lastName
          email
          id
          phone
          addresses {
            address1
            address2
            zip
            province
          }
        }
      }
    }
  }`

 

 

 

 

 

 

However, when I plug the id I get from that call into this mutation query:

 

 

 

  let queryString = `
    mutation updateCustomer($input: CustomerInput!) {
      customerUpdate(input: $input) {
        customer {
          id
          email
          phone
          addresses {
            address1
            address2
            zip
            city
            province
          }
        }
        userErrors {
          field
          message
        }
      }
    }
  `

 

 

 

 

I get a 200 response from the API with this error under an undefined customer value (though to be fair the 200 is coded in by me when I send the response to the front-end):

 

 

 

{"body":{"data":{"customerUpdate":{"customer":null,"userErrors":[{"field":["id"],"message":"Customer does not exist"}]}}

 

 

 

 

 

And this is the payload:

 

 

 

{"id":"gid://shopify/Customer/6990587593021","email":"ayu@test.com","addresses":[{"phone":"+16135551127"}]}

 

 

 

 

 

 

So my question is, am I using the Storefront API for the second call and the Admin API for the first one? The first call doesn't ask me for an auth so that's what has me confused, it shouldn't even let me query customers without a token if that were the case right?

 

I tried the same query on the GraphiQL app installed on my dev store and it works just fine too.

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 509

This is an accepted solution.

Hey @vlgwlf - based on the payload you shared, I believe this should work. Just want to confirm though - are you using the same payload on a different shop? If so, while each customer ID is unique across all shops, they can't be shared across different shops. If you're trying to use customer ID 6990587593021 on a different shop than the customer record was created on, this could explain why you're seeing the error. 

I don't believe this would have an effect on if you're using the Storefront API or the Admin API, but you're definitely correct that you would need a Storefront API access token in order to make queries via the Storefront API. 

If you're still encountering the error even after confirming the above, please get in touch with our Partner Support team directly through the support menu in your partner dashboard. Just link to this thread and share any relevant details (an X-Request-ID from the API Response header would be super helpful if possible to share). 

Thanks again for getting in touch - hope this helps/makes sense.

Al | Shopify Developer Support 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 509

This is an accepted solution.

Hey @vlgwlf - based on the payload you shared, I believe this should work. Just want to confirm though - are you using the same payload on a different shop? If so, while each customer ID is unique across all shops, they can't be shared across different shops. If you're trying to use customer ID 6990587593021 on a different shop than the customer record was created on, this could explain why you're seeing the error. 

I don't believe this would have an effect on if you're using the Storefront API or the Admin API, but you're definitely correct that you would need a Storefront API access token in order to make queries via the Storefront API. 

If you're still encountering the error even after confirming the above, please get in touch with our Partner Support team directly through the support menu in your partner dashboard. Just link to this thread and share any relevant details (an X-Request-ID from the API Response header would be super helpful if possible to share). 

Thanks again for getting in touch - hope this helps/makes sense.

Al | Shopify Developer Support 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog