GraphQL Parse Error in Android App Integration
I’m building an Android application that connects to Shopify and I keep getting a parse error when trying to add new users to the system. The error shows up as a parse issue with curly braces but I can’t figure out what’s wrong with my syntax.
My GraphQL Mutation Code
const userMutation = `mutation createUser($data: CustomerCreateInput!) {
customerCreate(input: $data) {
customer {
acceptsMarketing
email
firstName
lastName
password
phone
}
customerUserErrors {
field
message
code
}
}
}`;
const userData = {
"data": {
"acceptsMarketing": false,
"email": "[email protected]",
"firstName": "Jane",
"lastName": "Doe",
"password": "MyPass123",
"phone": "555-0123-456"
}
};
async function executeQuery(mutation, variables) {
return fetch('https://mystore.myshopify.com/api/graphql.json', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Shopify-Storefront-Access-Token': accessToken,
},
body: JSON.stringify({
query: mutation,
variables: variables
})
})
.then(res => res.json())
.then(data => console.log('Success:', data))
.catch(err => console.log('Failed:', err.message));
}
Error Message I Get
{"errors": [{"locations": [Array], "message": "Parse error on \"{\" (LCURLY) at [16, 20]"}]}
Any ideas what might be causing this parsing issue? I’ve been stuck on this for hours and would really appreciate some help from anyone who has worked with Shopify’s GraphQL API before.
I ran into something similar a few months back when working on a customer portal integration. The issue you’re facing is likely related to your variable structure. Your userData object has the data nested under a “data” key, but your mutation expects the variable to be called $data directly.
Try flattening your userData object like this:
const userData = {
“acceptsMarketing”: false,
“email”: “[email protected]”,
“firstName”: “Jane”,
“lastName”: “Doe”,
“password”: “MyPass123”,
“phone”: “555-0123-456”
};
Then pass it as:
executeQuery(userMutation, { data: userData });
The parse error at position [16, 20] usually indicates GraphQL is having trouble interpreting the variable substitution. Also double-check that your Storefront API token has the necessary permissions for customer creation mutations, as some tokens are read-only by default.
Had this exact same issue last week! the problem is your using the wrong endpoint - customer creation needs admin api access, not storefront. switch to /admin/api/2023-10/graphql.json
and use a private app token instead. storefront api dosent support customer mutations like that.
Looking at your code, the parse error is most likely stemming from how you’re structuring the GraphQL query itself. I’ve encountered this exact error before when there was a mismatch between the mutation definition and variable usage. The problem appears to be that you’re defining $data: CustomerCreateInput!
but then using individual fields directly in your customer object. You should either restructure your mutation to accept individual parameters or adjust how you’re passing the data. Also worth checking - make sure you’re using the correct API endpoint. For customer creation mutations, you might need to use the Admin API (/admin/api/2023-10/graphql.json
) instead of the Storefront API, depending on your access level. The Storefront API has limited mutation capabilities compared to the Admin API. Another thing to verify is that your mutation syntax matches Shopify’s current schema version. Sometimes deprecated fields or incorrect field types can cause parsing errors that manifest as brace-related issues.
This parsing error usually happens when there’s a schema mismatch or malformed variable passing. I faced something similar when integrating with Shopify’s API last year. The main issue I discovered was that the CustomerCreateInput type expects a specific structure that differs from what you’re providing. Your mutation variable structure needs to match exactly what the schema expects. Also, make sure you’re handling the phone field correctly - Shopify can be picky about phone number formatting and validation. Another thing that caught me off guard was that some fields might be restricted or require additional validation depending on your shop’s configuration. Try using GraphQL introspection queries first to verify the exact schema structure your shop supports. You can also enable more detailed error logging in your network requests to see if there are additional validation errors being masked by the parse error. Sometimes what appears as a parsing issue is actually a downstream validation problem that gets reported incorrectly.
The parse error you’re seeing is happening because of inconsistent variable naming in your GraphQL operation. Your mutation defines the variable as $data
but when you call executeQuery, you’re passing the entire userData object directly instead of wrapping it properly. The correct approach is to pass your variables like this: executeQuery(userMutation, { data: userData })
where userData contains the flat customer fields. I spent hours debugging this same issue in my Shopify integration. Also worth noting that your current mutation structure assumes you’re using the Admin API, but your endpoint suggests Storefront API which has different capabilities and schema requirements for customer operations.