Development discussions around Shopify APIs
Hi
Im reviewing my GDPR hooks code against the Shopify tutorial -
One thing Im not clear on is whether I need register the mandatory hooks, or are they preregistered?
If I consider the server.js example in the above tutorial then would I expect an implementation like -
Id expect the code to be -
server.use( createShopifyAuth({ apiKey: SHOPIFY_API_KEY, secret: SHOPIFY_API_SECRET_KEY, scopes: ['read_products', 'write_products'], async afterAuth(ctx) { const { shop, accessToken } = ctx.session; ctx.cookies.set("shopOrigin", shop, { httpOnly: false }); const registration = await registerWebhook({ address: `${HOST}/webhooks/products/create`, topic: 'PRODUCTS_CREATE', accessToken, shop, apiVersion: ApiVersion.October19 }); const registrationRedact = await registerWebhook({ address: `${HOST}/webhooks/customers/redact`, topic: 'customers/redact', accessToken, shop, apiVersion: ApiVersion.October19 }); await getSubscriptionUrl(ctx, accessToken, shop); } }) ); const webhook = receiveWebhook({ secret: SHOPIFY_API_SECRET_KEY }); router.post('/webhooks/products/create', webhook, (ctx) => { console.log('received webhook: ', ctx.state.webhook); }); router.post('/webhooks/customers/redact', webhook, (ctx) => { console.log('received webhook: ', ctx.state.webhook); });
Is this correct?
Hey 🙂
I just went through this recently myself. My understanding is that you cannot register the GDPR URLs in the same was as ordinary Shopify webhooks. You have to implement your own endpoints and provide the three URLs to Shopify when creating the app.
Even though they are custom URLs, the calls to them can still be validated to make sure they come direct from Shopify in the same way that webooks are validated.
Hope that helps! Let me know if I can clarify anything!
Hi
I ended up writing a little script to generate the shopify checksum for my GDPR messages to allow me to test this
The advantage was that I could send multiple messages to the endpoint through a rest client so sped up development
I need to post the script or do a blog post
I'm still struggling to implement webhooks from the shopify koa sample application.
Should I still use this pattern?
const webhook = receiveWebhook({ secret: SHOPIFY_API_SECRET });
router.post("/gdpr/shop/redact", webhook, (ctx) => {
console.log("received webhook: ", ctx.state.webhook);
ctx.body = { message: "No shop data is stored" };
});
User | RANK |
---|---|
8 | |
7 | |
3 | |
3 | |
3 |
Connect your PayPal account to allow your customers to checkout using the PayPal gateway a...
ByYour online store speed can enhance your store’s discoverability, boost conversion rates a...
ByShopping is at our fingertips with mobile devices. Is your theme optimized to be user-frie...
By