We have an app registered on Shopify. Our webhooks have stopped working for the last few days for some of the stores. We tried to re-register the webhook with the new API version, but no luck there too.
Has someone here faced a similar issue too?
We have an app registered on Shopify. Our webhooks have stopped working for the last few days for some of the stores. We tried to re-register the webhook with the new API version, but no luck there too.
Has someone here faced a similar issue too?
yes use this gdpr.js in your shopify app
import { DeliveryMethod, createHmac } from "@shopify/shopify-api";
export default {
/**
* Customers can request their data from a store owner. When this happens,
* Shopify invokes this webhook.
*
* https://shopify.dev/docs/apps/webhooks/configuration/mandatory-webhooks#customers-data_request
*/
CUSTOMERS_DATA_REQUEST: {
deliveryMethod: DeliveryMethod.Http,
callbackUrl: "/api/webhooks",
callback: async (topic, shop, body, webhookId) => {
const payload = JSON.parse(body);
// Payload has the following shape:
// {
// "shop_id": 954889,
// "shop_domain": "{shop}.myshopify.com",
// "orders_requested": [
// 299938,
// 280263,
// 220458
// ],
// "customer": {
// "id": 191167,
// "email": "john@example.com",
// "phone": "555-625-1199"
// },
// "data_request": {
// "id": 9999
// }
// }
},
},
/**
* Store owners can request that data is deleted on behalf of a customer. When
* this happens, Shopify invokes this webhook.
*
* https://shopify.dev/docs/apps/webhooks/configuration/mandatory-webhooks#customers-redact
*/
CUSTOMERS_REDACT: {
deliveryMethod: DeliveryMethod.Http,
callbackUrl: "/api/webhooks",
callback: async (topic, shop, body, webhookId) => {
const payload = JSON.parse(body);
// Payload has the following shape:
// {
// "shop_id": 954889,
// "shop_domain": "{shop}.myshopify.com",
// "customer": {
// "id": 191167,
// "email": "john@example.com",
// "phone": "555-625-1199"
// },
// "orders_to_redact": [
// 299938,
// 280263,
// 220458
// ]
// }
},
},
/**
* 48 hours after a store owner uninstalls your app, Shopify invokes this
* webhook.
*
* https://shopify.dev/docs/apps/webhooks/configuration/mandatory-webhooks#shop-redact
*/
SHOP_REDACT: {
deliveryMethod: DeliveryMethod.Http,
callbackUrl: "/api/webhooks/shop/redact",
callback: async (topic, shop, body, headers) => {
const hmac = headers["x-shopify-hmac-sha256"];
const secret = process.env.SHOPIFY_APP_SECRET_KEY; // your app's secret key
// Verify the HMAC digest
const digest = createHmac("sha256", secret)
.update(body, "utf8")
.digest("base64");
if (digest !== hmac) {
// Return a 401 (Unauthorized) response code if the digest doesn't match
return {
statusCode: 401,
body: "Unauthorized",
};
}
// Process the webhook payload if the digest is valid
const payload = JSON.parse(body);
// Payload has the following shape:
// {
// "shop_id": 954889,
// "shop_domain": "{shop}.myshopify.com"
// }
// ... your webhook processing logic ...
},
},
};