Using the API
Everything done in Hookdeck's UI can be achieved programmatically using our REST API.
API Reference
REST API Reference for api.hookdeck.com
Why use the API
Creating and updating webhook connections via the API lets you version control features like filters and transformations within your code. The API is also very useful for integrating Hookdeck into your CD & CI workflow.
Examples
The following examples are in JavaScript using Axios for HTTP requests.
Creating a connection
Here's how to programmatically create a connection in Hookdeck.
Create a connection idempotently
javascript
Axios.post('https://api.hookdeck.com/2023-07-01/webhooks', {
auth: {
user: 'REPLACE_WITH_API_KEY',
},
data: {
name: 'my-api-prod',
// Using a name will make the request indempotent. It's completely fine to create the same connection over and over again.
source: {
name: 'github-prod',
},
destination: {
name: 'my-api-prod',
url: '$ENDPOINT_URL',
},
},
});
Version controlling your filters
Filters allow you to filter incoming webhooks so you receive only the events that are meaningful to you.
javascript
// Receive events only once Shopify product is sold out (inventory is 0)
Axios.post('https://api.hookdeck.com/2023-07-01/webhooks/:YOUR_WEBHOOK_ID', {
auth: {
user: 'REPLACE_WITH_API_KEY',
},
data: {
filters: {
body: {
type: 'product/updated',
variants: {
inventory_quantity: 0,
old_inventory_quantity: {
$gte: 0,
},
},
},
},
},
});