-
-
Notifications
You must be signed in to change notification settings - Fork 375
Creating Webhooks
Create a new job via php artisan shopify-app:make:webhook [name] [topic]
.
The first argument is the class name for the job, the second is the Shopify topic/event for the webhook.
Example: php artisan shopify-app:make:webhook OrdersCreateJob orders/create
will create a webhook job file in App/Jobs/OrdersCreateJob.php
where you can easily modify the handle
method to do what you need with the webhook data.
Note: Webhooks will not work with localhost. Addresses must be publicly accessible by Shopify.
Example of an entry in config/shopify-app.php
:
// ...
'webhooks' => [
[
'topic' => 'orders/create',
'address' => 'https://some-app.com/webhook/orders-create'
],
],
// ...
When a shop logs into your app, this webhook entry will automatically be installed and App/Jobs/OrdersCreateJob
will be ready to accept data.
There is a route defined in this pacakge which links /webhook/{type}
to WebhookController
. The controller will attempt to find a job for {type}
in App/Jobs
of your application. It converts the hyphenated type
into PascelCase.
Example, if you create a webhook entry in config/shopify-app.php
with an address of https://(your-domain).com/webhook/orders-create
the controller will look for a job App/Jobs/OrdersCreateJob
.
-
/webhook/customers-update
=>App/Jobs/CustomersUpdateJob
-
/webhook/super-duper-hook
=>App/Jobs/SuperDuperHookJob
- etc...
If it fails to find the job, it will abort with a 500 HTTP status. If it is successfull in dispatching the job, it will return a empty body with a 201 HTTP status.
If you want to handle the dispatch of a job yourself, you may define a POST route in your routes/web.php
to point to your own controller.
Route::post(
'/webhook/some-string-here',
'App\Http\Controllers\CustomWebhookController'
)
->middleware('auth.webhook')
Be sure to add the auth.webhook
as above to ensure incoming requests are verified.
Under URL, enter the URL where you would like data to be stored. It is important to note that webhooks cannot be returned to the following URLs:
- Localhost
- Any URL ending in the word "internal" (i.e. thisshop.com/internal)
- "Fake" domains like www.example.com
- Shopify domains (i.e. shopify.com and myshopify.com)
- "Shopify" word is restricted in URL. Make sure it not included anywhere in the URL.
Under URL, enter the URL where you would like data to be stored. It is important to note that webhooks cannot be returned to the following URLs:
- Localhost
- Any URL ending in the word "internal" (i.e. thisshop.com/internal)
- "Fake" domains like www.example.com
- Shopify domains (i.e. shopify.com and myshopify.com)
- "Shopify" word is restricted in URL. Make sure it not included anywhere in the URL.
road map
Welcome to the wiki!
Please see the homepage for a list of relevant pages.