Webhooks (closed beta)
In this guide, we will look at how to register and consume webhooks to integrate your app with VDH-Solar. With webhooks, your app can know when something happens in VDH-Solar, such as status updates for an order or newly available products.
Registering webhooks
To register a new webhook, you need to have a URL in your app that VDH-Solar can call. You can configure a new webhook from the VDH-Solar dashboard under API settings. Give your webhook a name, pick the events you want to listen for, and add your URL.
Now, whenever something of interest happens, a webhook is fired off by VDH-Solar. In the next section, we'll look at how to consume webhooks.
Consuming webhooks
When your app receives a webhook request from VDH-Solar, check the type
attribute to see what event caused it. The first part of the event type will tell you the payload type, e.g., a order, product, etc.
Example webhook payload
{
"id": "a056V7R7NmNRjl70",
"type": "order.updated",
"payload": {
"id": 12345
// ...
}
}
In the example above, an order was updated
, and the payload type is a order
.
Event types
- Name
order.created
- Description
A new order was created.
- Name
order.updated
- Description
An existing order was updated.
- Name
order.deleted
- Description
An order was successfully deleted.
- Name
product.created
- Description
A new product was created.
- Name
product.updated
- Description
An existing product was updated.
- Name
product.deleted
- Description
A product was successfully deleted.
- Name
stock.updated
- Description
The stock of a product was updated.
Example payload
{
"id": "a056V7R7NmNRjl70",
"type": "stock.updated",
"payload": {
"product_id": 12345,
"stock": 1042,
}
}
Security
To know for sure that a webhook was, in fact, sent by VDH-Solar instead of a malicious actor, you can verify the request signature. Each webhook request contains a header named x-vdh-solar-signature
, and you can verify this signature by using your secret webhook key. The signature is an HMAC hash of the request payload hashed using your secret key. Here is an example of how to verify the signature in your app:
Verifying a request
$signature = $request['headers']['x-vdh-solar-signature'];
$hash = hash_hmac('sha256', $payload, $secret);
if (hash_equals($hash, $signature)) {
// Request is verified
} else {
// Request could not be verified
}
If your generated signature matches the x-vdh-solar-signature
header, you can be sure that the request was truly coming from VDH-Solar. It's essential to keep your secret webhook key safe — otherwise, you can no longer be sure that a given webhook was sent by VDH-Solar. Don't commit your secret webhook key to GitHub!