HI ,Acutully I created custom app using node js as for shopif documentation , in custom app I am trying read products/create data using webhook , I used Admin api to create topic on webhook store side but in the app I am not able to register product_create in webhook ,
Below code I am using for register PRODUCT_CREATE in node app but failing and I tried GraphSQL using command line that alos failing. I pasted error for the below.
const registrationCartUpdate = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
path: '/webhooks',
topic: 'PRODUCTS_CREATE',
apiVersion: Shopify.Context.API_VERSION,
webhookHandler: async (_topic, shop, body) => {
console.log('received cart update webhook: ');
//Print body
console.log(body);
},
});
if (registrationCartUpdate.success) {
console.log('Successfully registered cart update webhook!');
} else {
console.log('Failed to register PRODUCTS_CREATE webhook', registrationCartUpdate.result);
}
app.post("/webhooks", async (req, res) => {
try {
await Shopify.Webhooks.Registry.process(req,res);
console.log(`Webhook processed, returned status code 200);
} catch (error) {
console.log(`Failed to process webhook: ${error}`);
if (!res.headersSent) {
res.status(500).send(error.message);
}
}
});
ERROR ----:
Failed to register PRODUCTS_CREATE webhook undefined
┃ Failed to process webhook: Error: Could not validate request for topic products/create
┃ Failed to process webhook: Error: Could not validate request for topic products/create
Graph sql ----
curl -X POST \
https://test.myshopify.com/admin/api/2022-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: access_token‘\
-d '{
"query": "mutation webhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $webhookSubscription: WebhookSubscriptionInput!) { webhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) { webhookSubscription { id topic format endpoint { __typename ... on WebhookHttpEndpoint { callbackUrl } } } } }",
"variables": {
"topic": "PRODUCTS_CREATE",
"webhookSubscription": {
"callbackUrl": "
https://87fa-49-205-136-59.ngrok.io/webhooks",
"format": "JSON"
}
}
}'
ERROR :
{"data":{"webhookSubscriptionCreate":{"webhookSubscription":null}},"extensions":{"cost":{"requestedQueryCost":11,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":990,"restoreRate":50.0}}}}% venm2@WKMZT900CE0B testapp %