Why am I getting a GraphQL error in my customer payment method code?

Why am I getting a GraphQL error in my customer payment method code?

masumluf
Excursionist
38 0 9

Hello Developers, 

I have written below gql code but getting error . error is not clear, my code is, 

 

      const mailResponse = await client.query({
        data: `mutation customerPaymentMethodSendUpdateEmail(gid://shopify/CustomerPaymentMethod/${paymentId}: ID!) {
          customerPaymentMethodSendUpdateEmail(customerPaymentMethodId: $customerPaymentMethodId) {
            customer {
              # Customer fields
              id
              email
            }
            userErrors {
              field
              message
            }
          }
        }
        `,
      });

 

and error is 

 

┃ [{"message":"Parse error on \"gid\" (IDENTIFIER) at [1, 47]","locations":[{"line":1,"column":47}]}] mailResponse

 

 

Replies 2 (2)

toobiza
Shopify Partner
35 5 7

I think the issue is coming from the parsing of id parameter of the mutation. See this example here https://stackoverflow.com/questions/56090799/shopify-graphql-mutation-returns-parse-error-on-gid-ide...

 

i would recommend using the variables keyword defined within the query client see example here for node js. Note that the id is passed through the variable and not directly:

https://shopify.dev/api/admin-graphql/2022-04/mutations/customerDelete 

 

All the best!

oscprofessional
Shopify Partner
16115 2409 3123

Hello @masumluf 

The error message you received indicates a parse error in your GraphQL code. Specifically, it mentions an issue with the "gid" identifier at line 1, column 47. It seems that the GraphQL parser encountered an unexpected "gid" token at that position.

To resolve this error, you can try the following:

  1. Check the syntax of your GraphQL code and ensure that all identifiers, such as "gid," are valid and properly used.

  2. Make sure you have imported any necessary dependencies or libraries for the "client" object you are using.

  3. Verify that the variable $customerPaymentMethodId is defined and properly passed as a variable to the GraphQL query. It seems that you are using it in the query but it's not included in the code snippet you provided.

Here's an updated version of your code with some modifications and corrections:

 

const mailResponse = await client.query({
  query: `
    mutation customerPaymentMethodSendUpdateEmail($customerPaymentMethodId: ID!) {
      customerPaymentMethodSendUpdateEmail(customerPaymentMethodId: $customerPaymentMethodId) {
        customer {
          id
          email
        }
        userErrors {
          field
          message
        }
      }
    }
  `,
  variables: {
    customerPaymentMethodId: paymentId, // Assuming paymentId is defined and contains the actual ID
  },
});

 

Please review and adapt the code based on your specific requirements and the surrounding context.
Thanks

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free