MINIMUM SALEOR VERSION
3.5.10
MINIMUM SALEOR CLI VERSION
1.13
After you have installed your first App and learned how to develop its new features, it is time to extend its capabilities. Saleor platform allows developers to use webhooks, which can be set to notify the App about certain events i.e. creating a new order, updating a category, sending an invoice, and many more. The architectural details of webhooks and the complete list of webhook events are available in the docs.
After finishing this guide, you'll have accomplished the following:
You will extend the Saleor template App with a webhook that will send notifications over the HTTPS every time a product is updated.
saleor login
in the Terminal to accomplish that.In this step, you're going to generate a boilerplate code to handle incoming webhook notifications in your App. The data is going to be displayed in the console.
saleor app generate webhook
.PRODUCT_UPDATED
event and press Enter.You can now inspect the newly created handler in api/webhooks/product-updated.ts
file. As you can see, the handler's job is simply to log out the request body in the console.
Let's hook up our handler to the webhook instance created in Saleor.
saleor webhook create
.https://[app-in-your-environment.saleor.live]/api/webhooks/product-updated
PRODUCT_UPDATED
event and press Space to select it.string
with the subscription query.After a successful install, you will be provided with the webhook id
and are ready to test and verify its functionality.
For your webhook to send a notification to the handler, you need to trigger an action of updating a product. Let's quickly initiate an event in Saleor with the help of the Saleor CLI.
saleor trigger
command.query FetchTwelveProducts {
products(first: 12, channel: "default-channel") {
edges {
node {
id
name
thumbnail {
url
}
category {
name
}
}
}
}
}
id
of the first product.saleor trigger --id=
and paste the id
you have just copied, without the quote marks, e.g.
saleor trigger --id=UHJvZHVjdDo3Mg==
and hit Enter.You can also use your Saleor Dashboard to trigger the event.
Go to your code editor and check up on the local server console. You should be provided with a payload object describing your newly triggered action:
[
{
"type": "Product",
"id": "UHJvZHVjdDo3Mg==",
"category": {
"type": "Category",
"id": "Q2F0ZWdvcnk6MTQ=",
"name": "Juices",
"slug": "juices"
},
"collections": null,
"meta": {
"issued_at": "2022-07-21T06:31:47.479000+00:00",
"version": "3.5.1",
"issuing_principal": {
"id": "VXNlcjoyMg==",
"type": "user"
}
},
"attributes": [
{
"name": "Flavor",
"input_type": "dropdown",
"slug": "flavor",
"entity_type": null,
"unit": null,
"id": "QXR0cmlidXRlOjE2",
"values": [
{
...