For discussing the development and usage of Checkout UI extensions, post-purchase extensions, web pixels, Customer Accounts UI extensions, and POS UI extensions
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
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]
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.
Thanks! It's worked for me!
@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?
A web folder is not generated while creating the web-pixel extension. so where should we add the code?
@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}]}]}