What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

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
1831 273 421

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
1831 273 421

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...