Focuses on API authentication, access scopes, and permission management.
Hi everyone,
I've been trying to set up the headless Customer Accounts API for a client and I've run into some trouble. I've managed to successfully generate an access_token using the /auth/oauth/token endpoint, but when I try and use the token to actually query the API, I get a 401 response saying the token is invalid.
I am following the docs here, which say to structure your requests like so:
const response = await fetch(
'https://shopify.com/<shop-id>/account/customer/api/unstable/graphql',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: {access_token},
},
body: JSON.stringify({
operationName: 'SomeQuery',
'query { personalAccount { email }}',
variables: {},
}),
},
Here is the relevant request I am trying to make:
const fetchCustomer = async (accessToken) => {
const response = await axios.post(
`${process.env.NEXT_PUBLIC_CUSTOMER_ACCOUNT_API_URL}/account/customer/api/unstable/graphql`,
{
query: `
query getCustomer {
customer {
id
}
}
`,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: accessToken,
},
}
);
const customer = cleanGraphQLResponse(response?.data?.data?.customer);
setState((prev) => ({ ...prev, customer }));
};
I ran into the same issue.
How did you get an access token ?
Did you figure this out? I'm running into the same issue.