Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Failed to process webhook: Error: Could not validate request HMAC

Failed to process webhook: Error: Could not validate request HMAC

Neli2404
Shopify Partner
13 1 2

Hi everybody, when I tried to migrate to new Node template, the webhooks always throws this error: “Error: Could not validate request HMAC”.

Does anyone know how to fix this? I tried searching on Google but nothing works. This is my code snippet:

app.post(
	shopify.config.webhooks.path,
	express.text({ type: "*/*" }), // Even with this, it still throws the error No body was received when processing webhook
	function (req: any, res: any, next: any): any { // This one fix the error above
		req.body = JSON.stringify(req.body);
		next();
	},
	shopify.processWebhooks({ webhookHandlers: GDPRWebhookHandlers as any })
);
Replies 4 (4)

Liam
Community Manager
3108 344 899

Hi Nam7911,

 

There's a couple things you could do here to troubleshoot this HMAC validation error:

 

Verify the webhook path: First off you should double-check that the shopify.config.webhooks.path value matches the webhook path you set in your Shopify Partner Dashboard or Admin. The webhook path should be the same in both places.

 

Verify the body parsing middleware: In your code snippet, you're using express.text({ type: "*/*" }) as the middleware to parse the request body. This might cause issues with the HMAC validation. Instead, you can use express.json() middleware to parse the request body as JSON.

 

You could also verify the webhook secret and ensure that you have correctly set the webhook secret in your Shopify Partner Dashboard or Admin.

 

Hope these options help - if not let us know here and we'll dig into this a bit more.

 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Neli2404
Shopify Partner
13 1 2

Thanks for replying Liam,

I have double-checked the webhook path, they are identical, which is why I think they ran in the first place, which gave me the error.

 

For the "express.text({ type: "*/*" })" middleware, I followed the docs here https://github.com/Shopify/shopify-api-js/blob/main/docs/guides/webhooks.md#note-regarding-use-of-bo...

Basically how I understand is the new webhook will only take the rawBody, which is a string. Hence the use of the middleware (Although it doesn't work).

 

Can you point out to me where to find the set up for the webhook secret in Partner Dashboard? I tried looking everywhere and couldn't find anything.

julianbenegas
Shopify Partner
1 0 0

Any update here? I'm getting the same issue.

jana43
Shopify Partner
4 0 3

I had fixed this by following this step -

 

  1. npm run dev -- --reset, create a new app 
  2. Go to your partner's dashboard and click on all apps
  3. Click on your app
  4. Click on app setup
  5. Scroll to the bottom to find "Protected customer data access" 
  6. Check all the options from up to down don't miss anything, and save.
  7. Install the app
  8. Create an order to see whether the webhooks are working or not.

I followed these steps and it's worked for me.