HTTP_X_SHOPIFY_HMAC_SHA256 error in Laravel

Barry1
Shopify Expert
11 0 1

I ma trying to set up an api that works off a webhook. I have set up the webhook in shopify and then in the laravel controller I have added the php code as per the shopify doc s

https://help.shopify.com/api/getting-started/webhooks#verify-webhook

 

Problem is I keep getting an error: 

(1/1) ErrorException

Undefined index: HTTP_X_SHOPIFY_HMAC_SHA256

Any help greatly appreciated

0 Likes
Alex
Shopify Staff
Shopify Staff
1555 81 293

Hey Barry,

On an absolutely basic level I can't replicate this behaviour. With some logging set up for a standard webhook posts route, I'm finding the index just fine in webhook request header arrays:

Route::post('/webhooks', function()
{
  Log::info($_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256']);
});

If I had to guess, maybe the shift in context from route to controller is where the values of $_SERVER are being lost?

Cheers.

0 Likes
Barry1
Shopify Expert
11 0 1

I Managed to get this working by having the verification in a controller and routing to the controller, but it had to be in the construct, wouldnt work in the index method

javedali
New Member
1 0 0

How did you solve this? I am also facing the same problem. I am trying to recieve data from a webhook in Laravel. When I fire it to a route in Laravel and add the verify code into the route nothing happens. I also checked this: https://community.shopify.com/c/Shopify-APIs-SDKs/Shopify-webhooks-and-Laravel-routes/m-p/378017

This didn't work for me. Can you just tell me how did you included the PHP code in the controller and what modification you made in the routes?

0 Likes