Conditional Webhooks
Webhooks provide a streamlined approach to facilitate communication between applications, offering the advantage of receiving notifications whenever an app receives data from another app. They play a critical role in establishing an event-based communication channel, connecting application owners with Salla. The primary purpose of webhooks is to ensure the synchronization of data between two separate applications.
Webhooks form the foundation of the infrastructure that supports numerous online activities. By subscribing to a webhook, developers anticipate receiving a payload that contains relevant information pertaining to the events they are interested in. However, dealing with large volumes of content within these payloads can sometimes be overwhelming and challenging to navigate. This is where Salla Rules comes into play.
Salla Rules offers developers the ability to exercise control and customization over webhooks, utilizing the supported attributes. Rules enable the breakdown of simple business rules into smaller specification objects, which can later be combined to express more complex rules. This modular approach allows you as a developer to tailor their webhook experiences according to their specific needs and requirements.
Importance of Rules
Webhooks Targeting
Narrowing down the received payload is an achievable goal, as rules introduce you to conditional webhooks. Your communication now turns out to be an event-based communication with Salla, and the same is applied in the received payload.
Salla has provided the configurability feature to webhooks. In a sense, Rules contain basic filtering, which allow writing conditions and then afterwards receive particular payload based on the written condition.
As your business grows, you will need to redouble on your service quality served, accuracy delievred, and effort done. With rules, you can easily reduce the amount of the events you listen to, as they usually come loaded in payloads. That said, you only recieve the payloads you are in need in your app.
With rules, you get to head directly to take actions as decisions are easily made, and that means no more time wasted on time-consuming processes. Check for an overview of webhooks on Salla docs for more details.
Use Cases
The following are some use cases that webhooks can be used for:
- You can use rules in webhooks to filter updated carts that contain specific coupon codes.
- You can use rules in webhooks to uniquely identify specific order from a list of orders.
- You can also use rules in webhooks to recognize a specific product using its attributes (SKU, name, etc.).
General Standards in Attributes
Some Binary, Relational, and Logical operators are used when writing rules for a Salla webhook, such as equality, bitwise, and more.
Following the general standards is a must to obtain successful responses, so make sure to follow them. These rules act like conditional webhooks, for you to receive specific data.
Operations, expressions, and conditions to your webhook can be written. For instance, you may use =,!=,AND,OR
etc in such a manner: payment_method = YOUR_PAYMENT_METHOD
or in combination payment_method = mada OR price < 50
. That adds more capability to filter the response based on conditionalities. In the following section, you can look up more into how you can construct your own rules using real-world examples.
Write Your First Rule
The following payload registers a new webhook on the Merchant's dashboard, not on the Partners Portal, where the developer will be notified whenever the Merchant created an order.
{
"name": "Salla Order Created Event",
"event": "order.created",
"url": "https://webhook.site/a61ca376-dd98-4053-b2c4-8ba9cca470fc",
"version": 2,
"rule": "total > 100",
"headers": [
{
"key": "Authorization",
"value": "Your Secret token"
},
{
"key": "Accept-Language",
"value": "AR"
}
]
}
That said, you have successfully set your first webhook with rules. The next section will be rules to apply in other webhooks' events.
Examples
The following two examples showcase how conditional webhooks can be implemented practically in your webhook rules queries.
{
"name": "Salla Special Offer Created Event",
"event": "specialoffer.created",
"url": "https://webhook.site/a61ca376-dd98-4053-b2c4-8ba9cca470fc",
"version": 2,
"rule": "status = `active` OR applied_to = `first_order`",
"headers": [
{
"key": "Authorization",
"value": "Your Secret token"
},
{
"key": "Accept-Language",
"value": "AR"
}
]
}
In the above example the webhook was set the event to specialoffer.created
. In the rule section, we added OR
that means, when one of the conditions are true
, this wil trigger the webhook. In our example, the webhook will be triggered whenever there is a status
equaling to active
, or the the special offer created is applied to order
.
{
"name": "Salla Update Customer Event",
"event": "customer.created",
"url": "https://webhook.site/a61ca376-dd98-4053-b2c4-8ba9cca470fc",
"version": 2,
"rule": "city = `الرياض` AND location != `ØÙŠ اليرموك`",
"headers": [
{
"key": "Authorization",
"value": "Your Secret token"
},
{
"key": "Accept-Language",
"value": "AR"
}
]
}
In the above example, the webhook will be triggered whenever a customer has been created. In the rule section, we added And
;
that means that both conditions should be true
to trigger the webhook. In our example, the webhook will be triggered whenever the city is الرياض
and location is not the whereabouts of ØÙŠ اليرموك
.
Attributes
The following attributes allow you to write conditions only based on them. For example, if you want to write conditions for the Category
event, use in the rule
section one or more of the following:
id |
name |
parent_id |
status |
sort_order |
And the same logic goes for all the supported attributes.
Order
The supported events are the following:
Event Name |
---|
order.created |
order.updated |
order.status.updated |
order.cancelled |
order.refunded |
order.deleted |
order.products.updated |
order.payment.updated |
order.coupon.updated |
order.total.price.updated |
order.shipment.creating |
order.shipment.created |
order.shipment.cancelled |
order.shipment.return.creating |
order.shipment.return.created |
order.shipment.return.cancelled |
order.shipping.address.updated |
The rules can contain on or more of the following attributes:
Name | type |
---|---|
id |
Integer |
reference_id |
Integer |
date |
Date and Time |
customer_id |
Integer |
status_id |
Integer |
branch_id |
Integer |
coupon_code |
String |
feedback_status |
String |
total |
Float |
total_discount |
Float |
sub_total |
Float |
shipping_cost |
Float |
cash_on_delivery |
Float |
tax_percent |
String |
tax_amount |
Float |
currency |
String |
payment_method |
String |
payment_bank_id |
Integer |
shipment_id |
Integer |
shipment_pickup_id |
Integer |
shipment_tracking_link |
String |
shipment_company_id |
Integer |
shipment_company_name |
String |
shipment_receiver_name |
String |
shipment_receiver_email |
String |
shipment_receiver_phone |
String |
shipment_shipper_name |
String |
shipment_shipper_company_name |
String |
shipment_shipper_email |
String |
shipment_shipper_phone |
String |
shipment_pickup_address_country |
String |
shipment_pickup_address_city |
String |
shipment_pickup_address_shipping_address |
String |
shipment_pickup_address_street_number |
String |
shipment_pickup_address_block |
String |
shipment_pickup_address_postal_code |
String |
shipment_pickup_address_geo_lat |
String |
shipment_pickup_address_geo_lng |
String |
shipment_dropoff_address_country |
String |
shipment_dropoff_address_city |
String |
shipment_dropoff_address_shipping_address |
String |
shipment_dropoff_address_street_number |
String |
shipment_dropoff_address_block |
String |
shipment_dropoff_address_postal_code |
String |
shipment_dropoff_address_geo_lat |
Float |
shipment_dropoff_address_geo_lng |
Float |
Product
The supported events are the following:
Event Name |
---|
product.created |
product.updated |
product.deleted |
product.available |
product.quantity.low |
The rules can contain on or more of the following attributes:
Name | type |
---|---|
id |
Integer |
currency |
String |
promotion_title |
String |
promotion_sub_title |
String |
sku |
String |
type |
String |
name |
String |
short_link_code |
String |
price |
Float |
description |
String |
quantity |
Integer |
status |
String |
is_available |
boolean |
sale_price |
Float |
sale_end |
Integer or String |
require_shipping |
boolean |
cost_price |
Float |
weight |
Float |
with_tax |
boolean |
included_tax |
boolean |
url |
String |
has_special_price |
boolean |
regular_price |
Float |
max_items_per_user |
Integer |
show_in_app |
boolean |
notify_quantity |
Integer or String |
unlimited_quantity |
boolean |
managed_by_branches |
boolean |
brand_id |
Integer |
Customer
The supported events are the following:
Event Name |
---|
customer.created |
customer.updated |
customer.login |
customer.otp.request |
The rules can contain on or more of the following attributes:
Name | type |
---|---|
id |
Integer |
first_name |
String |
last_name |
String |
mobile |
String |
mobile_code |
String |
email |
String |
avatar |
String |
gender |
String |
birthday |
Date and Time |
city |
String |
country |
String |
currency |
String |
location |
String |
Special Offers
The supported events are the following:
Event Name |
---|
specialoffer.created |
specialoffer.updated |
The rules can contain on or more of the following attributes:
Name | type |
---|---|
id |
Integer |
name |
String |
message |
String |
offer_type |
String |
status |
String |
expiry_date |
Date and Time |
Category
The supported events are the following:
Event Name |
---|
category.created |
category.updated |
The rules can contain on or more of the following attributes:
Name | type |
---|---|
id |
Integer |
name |
String |
parent_id |
Integer |
status |
String |
sort_order |
Integer |
Brand
The supported events are the following:
Event Name |
---|
brand.created |
brand.updated |
brand.deleted |
The rules can contain on or more of the following attributes:
Name | type |
---|---|
id |
Integer |
name |
String |
status |
boolean |
custom_url |
String |
Cart
The supported event is the following:
Event Name |
---|
abandoned.cart |
The rules can contain on or more of the following attributes:
Name | type |
---|---|
id |
Integer |
subtotal |
Float |
currency |
String |
total |
Float |
coupon_code |
String |
customer_id |
Integer |
customer_avatar |
String |
customer_name |
String |
customer_mobile |
String |
created_at |
Date and Time |
updated_at |
Date and Time |
Miscellaneous
Event Name |
---|
review.added |
The rules can contain on or more of the following attributes:
Name | type |
---|---|
parent_id |
Integer |
store_id |
Integer |
customer_id |
Integer |
product_id |
Integer |
page_id |
Integer |
order_id |
Integer |
rating |
Integer |
content |
String |
status |
String |
ip_address |
String |
ip_city |
String |
ip_country |
String |
type |
String |