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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: Web Pixel Mutation Parse Error On ":" (STRING)

Web Pixel Mutation Parse Error On ":" (STRING)

ihsfr
Shopify Partner
14 1 1

I am trying to use the new webPixelCreate mutation. I am getting a syntax error when copying the snippet directly from here: https://shopify.dev/apps/pixels/pixels-getting-started#step-6-create-a-web-pixel-merchant-setting-fo...

 

Mutation string:

 

mutation {
  webPixelCreate(webPixel: { settings: "{\"accountId\":\"234\"}" }) {
    userErrors {
      code
      field
      message
    }
    webPixel {
      settings
      id
    }
  }
}

I have checked and the settings I am passing matches with the settings I created for the web pixel extension.

 

The error I am getting: 

 

error - Error: Parse error on ":" (STRING) at [2, 58]

 

Want to improve your Facebook Pixels or TikTok Pixels performance? Give us a try: https://apps.shopify.com/partners/galacticapps
Replies 6 (6)

Barnett4321
Shopify Partner
29 0 15

I made this file in sample app app-pixels/web/helpers/web-pixel-create.js

 

import { Shopify } from "@shopify/shopify-api";

export const DEFAULT_ACCOUNT_ID = "234";

const WEB_PIXEL_CREATE_MUTATION = `
mutation webPixelCreate($webPixel: WebPixelInput!) {
  webPixelCreate(webPixel: $webPixel) {
    userErrors {
      field
      message
    }
    webPixel {
      settings
    }
  }
}`;

export default async function webPixelCreate(session, accountID = DEFAULT_ACCOUNT_ID) {
  const client = new Shopify.Clients.Graphql(session.shop, session.accessToken);

  try {
    let resp = await client.query({
      data: {
        query: WEB_PIXEL_CREATE_MUTATION,
        variables: {
          webPixel: { 
            settings: { accountID: accountID } 
          }
        },
      },
    });
    console.log('webPixelSuccess', JSON.stringify(resp.body, null, 2));
  } catch (error) {
    if (error instanceof Shopify.Errors.GraphqlQueryError) {
      throw new Error(`${error.message}\n${JSON.stringify(error.response, null, 2)}`);
    } else {
      throw error;
    }
  }
}

 

 

Here's the docs:
https://shopify.dev/api/admin-graphql/2022-10/mutations/webPixelCreate


Also notice Shopify.Errors.GraphqlError variable. This differs from Shopify's default buggy code which uses ShopifyErrors.GraphqlError which doesn't work or exist.

gbamandacaetano
Shopify Partner
2 0 1

Thanks! It's worked for me! 

1080
Shopify Partner
301 9 66

@gbamandacaetano  Thanks for the posted here, it was good to know.
I am using the code as above mention. but still getting the Error.
can you please share your work around how it was worked for you? 

manju3
Shopify Partner
1 0 0

A web folder is not generated while creating the web-pixel extension. so where should we add the code?

1080
Shopify Partner
301 9 66

@manju3  use the CLI 3.x latest version so it will create. 

1080
Shopify Partner
301 9 66

@Barnett4321 I am using the same code you posted, while ruing this code is giving the error.
but the graph QL query is correct i think

{"errors":[{"message":"syntax error, unexpected STRING (\":\"), expecting COLON at [2, 58]","locations":[{"line":2,"column":58}]}]}