Headless commerce and custom storefronts with Shopify APIs and SDKs
Hi guys,
I'm trying to get CustomerAccessToken by querying GraphQL in my React App. So far, I tried testing on GraphiQL and everything worked just fine. However, when I tried querying in my React App, I got this error
""Variable $input of type CustomerAccessTokenCreateInput! was provided invalid value""
Sorry if this is a noobie question. GraphQL is pretty new for me.
Here's my code.
componentDidMount() {
const query = `
mutation customerAccessTokenCreate($input: CustomerAccessTokenCreateInput!) {
customerAccessTokenCreate(input: $input) {
customerAccessToken {
accessToken
expiresAt
}
customerUserErrors {
code
field
message
}
}
}
`
const input = {
"email": "myemail@gmail.com",
"password": "abcdefg"
}
fetch('https://my-store.myshopify.com/api/2020-07/graphql.json', {
method: 'POST',
headers: {
"Accept": "application/json",
"Content-Type": "application/graphql",
'X-Shopify-Storefront-Access-Token': `${storefrontAccessToken.shopifyCredentials}`
},
body: query,
variables: JSON.stringify({ input })
})
.then(res => res.json())
.then(data => console.log(data))
}
Not sure what am I missing here. I'd appreciate any help.
I managed to make it work like this
const customerInfo = {
email: "myemail@gmail.com",
password: "abcdefg"
}
const query = `
mutation customerAccessTokenCreate {
customerAccessTokenCreate(input: {
email: "${customerInfo.email}",
password: "${customerInfo.password}"
}) {
customerAccessToken {
accessToken
expiresAt
}
customerUserErrors {
code
field
message
}
}
}
`
Is there any other more concise ways ?
Thanks to all Community members that participated in our inaugural 2 week AMA on the new E...
By Jacqui Mar 10, 2023Upskill and stand out with the new Shopify Foundations Certification program
By SarahF_Shopify Mar 6, 2023One of the key components to running a successful online business is having clear and co...
By Ollie Mar 6, 2023