im working on shopify project to develop the android app. Currently im facing issue when creating customer. im tried to solve it if someone know about this please help me out!
Create customer mutation query
const query= `mutation customerCreate($input: CustomerCreateInput!) {
customerCreate(input: $input) {
customer {
acceptsMarketing
email
firstName
lastName
password
phone
}
customerUserErrors {
field
message
code
}
variables: {
"input": {
"acceptsMarketing": true,
"email": "[email protected]",
"firstName": "John",
"lastName": "Smith",
"password": "5hopify",
"phone": "111111111111"
}
},
}
}`;
async function apiCall(query) {
return fetch('https://storename.myshopify.com/api/graphql.json', {
method: 'POST',
headers: {
'Content-Type': 'application/graphql',
'Access-Control-Origin': '*',
'X-Shopify-Storefront-Access-Token': token,
},
body: query,
})
.then(response => response.json())
.then(response => console.log('response: ', response))
.catch(error => console.log('error: ', error.message));
}
facing the below error
{"errors": [{"locations": [Array], "message": "Parse error on \"{\" (LCURLY) at [16, 20]"}]}
CodePudding user response:
The error is telling you there's a parse* error on line 16 column 20. Parse errors usually point to typos, and my best guess is the :
you have after variables
on line 16 - is that symbol supposed to be there?
CodePudding user response:
Use the following query. its worked for me
mutation {
customerCreate(
input: {
firstName: "dave",
lastName: "smith",
email: "[email protected]",
password: "12345"
acceptsMarketing: true,
}
) {
customer {
id
firstName
lastName
email
}
userErrors {
field
message
}
customer {
id
}
}
}