I am creating an app for merchants and Shopify using laravel. I have configured and installed webhooks to send admins notifications when new customers are created in config/shopify.php
in my app.
shopify.php
use OseintowShopifyFacadesShopify;
use LaravelSocialiteFacadesSocialite;
use AppUser;
use AppStore;
use AppUserProvider;
use Auth;
$shopifyUser = Socialite::driver('shopify')->stateless()->user();
$shopUrl = $shopifyUser->nickname;
$accessToken = $shopifyUser->token;
Shopify::setShopUrl($shopUrl)->setAccessToken($accessToken)->post("admin/webhooks.json",
[
'webhook' =>
['topic' => 'customers/create',
'address' => 'https://shopify.kast.com/webhook',
'format' => 'json'
]
]);
Route
Route::post('/webhook', 'ReceiverController@webhook');
ReceiverController
public function webhook()
{
send sms/email to admin
}
Now when I configure the webhook in the shop admin settings and send a test notification or create a customer,I receive the SMS/emails
But when I delete the webhook settings from the admin page and create a new customer for the shop, I don’t receive the SMS.
Is there any error in shopify.php (webhook configuration) for my app?
PS: shop domain is founz.myshopify.com
and app is hosted https://shopify.kast.com
2
Answers
Most probably you didn’t register a webhook using access token.
If you’re using
OseintowShopify
, yourshopify.php
file should look like:Let it just holds your public app’s credentials.
It looks like you haven’t registered any webhook using access token. When you register a webhook using shopify admin, that webhook will be fired to all application. Don’t do that unless you know what you’re doing.
Instead try registering the same webhook using Postman with your access token and see if it is working. And then use your programming skills to automate it. Cheers!
There Can be two main reason for that.
1) Webhook could not created successfully. to check this Please make API call with
GET Request
If you did not get your desired webhook in the response please create it
2) In Laravel spacific development,you need to bypass VerifyCsrfToken middle-ware for your webhook route
as Laravel will not allow & blocks cross site requests default.to do so please follow below steps.
Go to app/http/middleware/VerifyCsrfToken & add your route in the $except array.
As Example :