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

ihsfr
Shopify Partner
6 0 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]

 

Replies 6 (6)

Barnett4321
Excursionist
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
291 8 42

@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
291 8 42

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

1080
Shopify Partner
291 8 42

@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}]}]}