Solved

Syntax for customerUpdate mutation using node.js and shopify-api-node

epodietz
Excursionist
13 2 1

I am new to GraphQL...I was able to do a customerUpdate mutation using the GraphQL playground, but when I try it in a node.js script (below) I get the following error: "Error updating customer: RequestError: Variable $input of type CustomerInput! was provided invalid value."

 

const Shopify = require('shopify-api-node');

const shopify = new Shopify({
    shopName: 'mystore.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();
 
Accepted Solution (1)

SBD_
Shopify Staff
1828 269 398

This is an accepted solution.

Hey @epodietz 

 

Looks like you're not passing the variables. You can pass them as a second argument to shopify.graphql like this:

 

const response = await shopify.graphql(query, variables);

 

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 2 (2)

SBD_
Shopify Staff
1828 269 398

This is an accepted solution.

Hey @epodietz 

 

Looks like you're not passing the variables. You can pass them as a second argument to shopify.graphql like this:

 

const response = await shopify.graphql(query, variables);

 

Scott | Developer Advocate @ Shopify 

epodietz
Excursionist
13 2 1

Thanks, Scott. Pretty obvious, in retrospect. Now to glue back those hairs that I pulled out...