GraphQL mutation error when adding new customer through Shopify API in Android app

GraphQL Parse Error When Adding Customer via Shopify API

I’m building an Android application that integrates with Shopify. I keep getting a parse error whenever I try to add a new customer using GraphQL mutations. The error mentions something about a parse issue with curly braces but I can’t figure out what’s wrong with my syntax.

My Current Implementation

const createUserMutation = `mutation addNewCustomer($customerData: CustomerCreateInput!) {
  customerCreate(input: $customerData) {
    customer {
      acceptsMarketing
      email
      firstName
      lastName
      phone
    }
    customerUserErrors {
      field
      message
      code
    }
  }
}`;

const mutationVariables = {
  "customerData": {
    "acceptsMarketing": false,
    "email": "[email protected]",
    "firstName": "Sarah",
    "lastName": "Doe",
    "password": "myPass123",
    "phone": "+1234567890"
  }
};

async function executeGraphQLQuery(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('API Response: ', data))
    .catch(err => console.log('Request failed: ', err.message));
}

Error I’m Getting

{"errors": [{"locations": [Array], "message": "Parse error on \"{\" (LCURLY) at [16, 20]"}]}

Has anyone encountered this type of parsing error before? What could be causing the issue with the curly brace syntax?

Had this exact same parsing error last year on a similar project. You’re mixing APIs - using the Storefront endpoint but trying to run an Admin mutation. Storefront API doesn’t support customerCreate at all, that’s why you’re getting the weird curly brace error. Switch to the Admin API endpoint /admin/api/2023-10/graphql.json and use a private app token instead of the storefront one. Also check that your app has write_customers permission in your Shopify partner dashboard - you’ll get auth errors even with the right endpoint if that’s missing. Your mutation syntax looks fine for Admin API though.

Yeah, everyone’s right about the API mismatch. These endpoint switches and permission configs are a nightmare every time.

I’ve hit this wall on multiple projects and got sick of wrestling with Shopify’s API layers. Now I skip the direct integration completely.

Set up an automation flow that handles the Shopify customer creation for you. Send customer data to a webhook endpoint - the automation routes it to the right Shopify API with proper credentials and error handling.

Your Android app stays simple. POST the customer data, get a clean response. No more guessing which endpoint to use or juggling token types.

I’ve built dozens of these flows - they’re rock solid. Way less debugging than handling Shopify’s API quirks in your app code.

Check out Latenode for this: https://latenode.com

Hit this exact issue a few months ago building a customer management feature. You’re mixing Admin API with Storefront API - that’s the problem. The customerCreate mutation only works with Admin GraphQL API, but you’re using a Storefront endpoint and token. Storefront API can’t create customers through GraphQL mutations like this. Two options: switch to Admin API endpoint with admin credentials, or use the REST API customer creation endpoint. If you go Admin API route, double-check your app has customer write permissions in Shopify settings - you’ll get auth errors otherwise, even with perfect syntax.

hey, just a thought, check your endpoint. looks like you’re trying to use customerCreate which is for admin API, but you might be hitting the storefront API. try /admin/api/2023-10/graphql.json and use an admin access token instead.