updateCustomer mutation using GraphQL, getting "CustomerInput! was provided invalid value"

Topic summary

A developer successfully executed an updateCustomer mutation in GraphQL playground but encountered a validation error when implementing it in Node.js using the shopify-api-node library.

Error received:

  • Variable $input of type CustomerInput! was provided invalid value
  • Occurs despite the mutation working in the playground environment

Solution provided:
Restructure the GraphQL request to match Shopify’s official documentation format:

  • Embed variables as a key within the query object rather than as a separate constant
  • Use the client.query() method with a data object containing both query and variables keys
  • Reference the official Shopify Admin GraphQL API documentation for customerUpdate mutation

Code structure:

const data = await client.query({
  data: {
    "query": `mutation customerUpdate($input: CustomerInput!) {...}`,
    "variables": { "input": {...} }
  }
});

Additional note: This issue was identified as a duplicate of an existing community thread addressing the same syntax problem.

Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

I was able to do updateCustomer in the GraphQL playground, but when I try to do it in node.js (see below) I get the following error:

Error updating customer: RequestError: Variable $input of type CustomerInput! was provided invalid value

at Request. (c:\nodejs\node_modules\got\dist\source\as-promise\index.js:113:42)

at afterResponse (c:\nodejs\node_modules\shopify-api-node\index.js:296:15)

at Request. (c:\nodejs\node_modules\got\dist\source\as-promise\index.js:87:42)

at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

{name: ‘RequestError’, code: ‘ERR_GOT_REQUEST_ERROR’, timings: {…}, locations: Array(1), path: undefined, …}

const Shopify = require(‘shopify-api-node’);

const shopify = new Shopify({

shopName: ‘myStoreAt.myshopify.com’,

accessToken:‘xxx’

});

const updateCustomer = async () => {

const query = `

mutation customerUpdate($input: CustomerInput!) {

customerUpdate(input: $input) {

userErrors { field, message }

customer { id, firstName, lastName }

}

} `

const variables= {

“input”: {

“id”: ‘gid://shopify/Customer/1018520244’,

“firstName”: ‘Frank’,

“lastName”: ‘Jones’

}

};

try {

const response = await shopify.graphql(query);

console.log(JSON.stringify(response, null, 2));

} catch (error) {

console.log(‘Error updating customer:’, error);

}

}

updateCustomer();

I would structure my GraphQl request as shown in the documentation and not assign “variables” as a constant but as a key within the query. Like this:

const data = await client.query({
  data: {
    "query": `mutation customerUpdate($input: CustomerInput!) {
      customerUpdate(input: $input) {
        userErrors {
          field
          message
        }
        customer {
          id
          firstName
          lastName
        }
      }
    }`,
    "variables": {
      "input": {
        "id": "gid://shopify/Customer/1018520244",
        "firstName": "Tobi",
        "lastName": "Lutke"
      }
    },
  },
});

You can see the documentation here. https://shopify.dev/docs/api/admin-graphql/2023-10/mutations/customerupdate

Duplicate https://community.shopify.com/topic/2396474 :slightly_smiling_face: