Skip to main content
POST
/
hooks
Register new hooks
curl --request POST \
  --url http://localhost:5001/hooks \
  --header 'X-blnk-key: <api-key>'
import requests

url = "http://localhost:5001/hooks"

headers = {"X-blnk-key": "<api-key>"}

response = requests.post(url, headers=headers)

print(response.text)
const options = {method: 'POST', headers: {'X-blnk-key': '<api-key>'}};

fetch('http://localhost:5001/hooks', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_PORT => "5001",
CURLOPT_URL => "http://localhost:5001/hooks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"X-blnk-key: <api-key>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"net/http"
"io"
)

func main() {

url := "http://localhost:5001/hooks"

req, _ := http.NewRequest("POST", url, nil)

req.Header.Add("X-blnk-key", "<api-key>")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("http://localhost:5001/hooks")
.header("X-blnk-key", "<api-key>")
.asString();
require 'uri'
require 'net/http'

url = URI("http://localhost:5001/hooks")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["X-blnk-key"] = '<api-key>'

response = http.request(request)
puts response.read_body
Use blnk.Hooks.create to register a webhook that Blnk calls before or after a transaction.
1

Call the method

blnk.Hooks.create
const response = await blnk.Hooks.create({
  name: 'Pre-transaction validation',
  url: 'https://api.example.com/validate',
  type: 'PRE_TRANSACTION',
  active: true,
  timeout: 30,
  retry_count: 3,
});
FieldTypeDescription
namestringDescriptive name for the hook.
urlstringEndpoint URL Blnk calls when the hook runs.
typestringPRE_TRANSACTION or POST_TRANSACTION.
activebooleanWhether the hook is enabled.
timeoutnumberMaximum time in seconds allowed for the hook to execute.
retry_countnumberMaximum number of retry attempts if the hook fails.
2

Save the hook ID

Use response.data.id to view, update, or delete the hook later.
3

Response

201 Created
{
  "id": "hk_test_123",
  "name": "Pre-transaction validation",
  "url": "https://api.example.com/validate",
  "type": "PRE_TRANSACTION",
  "active": true,
  "timeout": 30,
  "retry_count": 3,
  "created_at": "2024-11-26T08:36:36.238244338Z",
  "last_run": "0001-01-01T00:00:00Z",
  "last_success": false
}
FieldTypeDescription
idstringUnique ID for the hook. Use it to view, update, or delete the hook.
created_atstringDate and time the hook was created.
last_runstringDate and time the hook last executed.
last_successbooleanWhether the most recent execution succeeded.

How webhooks work

Hook types, payloads, and execution.

Register new hooks

HTTP request and response schema.

Need help?

We are very happy to help you make the most of Blnk, regardless of whether it is your first time or you are switching from another tool. To ask questions or discuss issues, please contact us or join our Discord community.