GraphQL error: Variable $customerAccessToken of type String! was provided invalid value

Solved
Highlighted
Excursionist
22 2 1

I'm attempting to recover a customer using the customerAccessToken that is given when the user logs in to Shopify.

Using Apollo, here's my code:

 

 

this.apollo.mutate({
  mutation: getCustomerFromToken,
  variables: {
    input: {
      customerAccessToken: '217b9a6952c28eb4db376487a6301294' // Also tried btoa('217b9a6952c28eb4db376487a6301294')
    }
  },
})

 

 

 

Here's my GraphQL query:

 

 

query getCustomerFromToken($customerAccessToken: String!) {
  customer(customerAccessToken: $customerAccessToken) {
    id
    addresses(first: 5) {
      edges {
        node {
        address1
        address2
        company
        city
        province
        zip
        country
        phone
        }
      }
    }
    orders(first: 200) {
      edges {
        cursor
        node {
          id
          totalPriceV2 {
            amount
            currencyCode
          }
          processedAt
          orderNumber
        }
      }
    }
  }
}

 

 

------------------------------------------------------------------------------

Here's the login GraphQL code I'm using to retrieve the accessToken from Shopify:

 

mutation customerAccessTokenCreate($input: CustomerAccessTokenCreateInput!) {
  customerAccessTokenCreate(input: $input) {
    customerAccessToken {
      accessToken
      expiresAt
    }
    customerUserErrors {
      code
      field
      message
    }
  }
}

 

0 Likes
Highlighted
Excursionist
22 2 1

This is an accepted solution.

My problem was two fold.

  1. I was using a mutation on a query end point
  2. Queries don't use input in the payload
const payload = {
    customerAccessToken: "..."
}

// NOT

const payload = {
  input: {
    customerAccessToken: "..."
  }
}

 

0 Likes