Focuses on API authentication, access scopes, and permission management.
I am using Customer Account API to use customer account in my application.
Considering the docs, it says I should use Access Token to make requests to gql, but I am always have this error:
"Not a valid access token".
They also have the mistake in the example:
const response = await fetch( 'https://shopify.com/<shop-id>/account/customer/api/2024-07/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: {access_token}, }, body: JSON.stringify({ operationName: 'SomeQuery', 'query { customer { emailAddress { emailAddress }}}', variables: {}, }), },
This code will never work, what is happening in the request body..??
This is how I try to make requests:
query(query) { if (!query) return; const headers = { 'Content-Type': 'application/json', Authorization: `${this.cookies.get('auth-token')}`, }; console.debug(headers); return this.fetch(this.baseUrl, { method: 'POST', headers, body: JSON.stringify({ query }), }); }
And my headers contain:
{ 'Content-Type': 'application/json', Authorization: 'atkn_****_****_****' }
API response in this case:
{ errors: [ { message: 'Not a valid access token' } ] }
I also have access token of authenticated user, and other stuff that docs described before "Endpoint and queries" section.
So how to make authenticated request to get my authenticated customer data?
Hi @Kkkkk3
Use 'X-Shopify Access Token' instead of 'Authorization'
const response = await fetch(
'https://shopify.com/<shop-id>/account/customer/api/2024-07/graphql',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': {access_token},
},
body: JSON.stringify({
operationName: 'SomeQuery',
'query { customer { emailAddress { emailAddress }}}',
variables: {},
}),
},