> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.fynapse.app/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.fynapse.app/_mcp/server.

# Setup Webhook Subscription via API

> Learn how to configure webhook subscriptions via API.

## Overview

This guide explains how to receive different events in your system using webhooks.

> **Info**
>
> Please note that Balance Extract webhook requires an additional step of configuring an extract in the UI. This additional step is described in [Event Types](/api-reference/getting-started/webhooks/event-types#balance-extract---balanceextracted-event)

## Before You Start

Make sure you are familiar with:

* Webhook concepts → [Webhooks Overview](/api-reference/getting-started/webhooks/core-concepts)
* Request validation → [Webhook Security](/api-reference/getting-started/webhooks/security)
* Delivery behavior and retries → [Delivery & Retries](/api-reference/getting-started/webhooks/delivery-retries)
* API access and permissions → [Webhook Configuration](/api-reference/getting-started/webhooks/configuration)

## Step 1 — Create a Webhook Secret

A webhook secret is used to sign requests so your system can verify their authenticity.

Create a secret using the API:

### Request

POST [https://api.fynapse.com/api/v1/event-deliveries/secrets](https://api.fynapse.com/api/v1/event-deliveries/secrets)

```curl
curl -X POST https://api.fynapse.com/api/v1/event-deliveries/secrets \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
  "name": "string"
}'
```

```python
import requests

url = "https://api.fynapse.com/api/v1/event-deliveries/secrets"

payload = { "name": "string" }
headers = {
    "Authorization": "<token>.",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.fynapse.com/api/v1/event-deliveries/secrets';
const options = {
  method: 'POST',
  headers: {Authorization: '<token>.', 'Content-Type': 'application/json'},
  body: '{"name":"string"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.fynapse.com/api/v1/event-deliveries/secrets"

	payload := strings.NewReader("{\n  \"name\": \"string\"\n}")

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

	req.Header.Add("Authorization", "<token>.")
	req.Header.Add("Content-Type", "application/json")

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

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

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.fynapse.com/api/v1/event-deliveries/secrets")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<token>.'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"string\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.fynapse.com/api/v1/event-deliveries/secrets")
  .header("Authorization", "<token>.")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"string\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.fynapse.com/api/v1/event-deliveries/secrets', [
  'body' => '{
  "name": "string"
}',
  'headers' => [
    'Authorization' => '<token>.',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.fynapse.com/api/v1/event-deliveries/secrets");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<token>.");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<token>.",
  "Content-Type": "application/json"
]
let parameters = ["name": "string"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.fynapse.com/api/v1/event-deliveries/secrets")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

* Store the returned `value` property securely.
* You will need it to validate webhook signatures.

## Step 2 — Create a Webhook Subscription

A subscription defines where events should be delivered.

### Request

POST [https://api.fynapse.com/api/v1/event-deliveries/subscriptions](https://api.fynapse.com/api/v1/event-deliveries/subscriptions)

```curl
curl -X POST https://api.fynapse.com/api/v1/event-deliveries/subscriptions \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
  "name": "Balance Webhook",
  "endpointUrl": "https://example.com/webhooks/balance",
  "eventTypes": [
    "balance.extracted"
  ]
}'
```

```python
import requests

url = "https://api.fynapse.com/api/v1/event-deliveries/subscriptions"

payload = {
    "name": "Balance Webhook",
    "endpointUrl": "https://example.com/webhooks/balance",
    "eventTypes": ["balance.extracted"]
}
headers = {
    "Authorization": "<token>.",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.fynapse.com/api/v1/event-deliveries/subscriptions';
const options = {
  method: 'POST',
  headers: {Authorization: '<token>.', 'Content-Type': 'application/json'},
  body: '{"name":"Balance Webhook","endpointUrl":"https://example.com/webhooks/balance","eventTypes":["balance.extracted"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

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

func main() {

	url := "https://api.fynapse.com/api/v1/event-deliveries/subscriptions"

	payload := strings.NewReader("{\n  \"name\": \"Balance Webhook\",\n  \"endpointUrl\": \"https://example.com/webhooks/balance\",\n  \"eventTypes\": [\n    \"balance.extracted\"\n  ]\n}")

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

	req.Header.Add("Authorization", "<token>.")
	req.Header.Add("Content-Type", "application/json")

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

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

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.fynapse.com/api/v1/event-deliveries/subscriptions")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<token>.'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Balance Webhook\",\n  \"endpointUrl\": \"https://example.com/webhooks/balance\",\n  \"eventTypes\": [\n    \"balance.extracted\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.fynapse.com/api/v1/event-deliveries/subscriptions")
  .header("Authorization", "<token>.")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Balance Webhook\",\n  \"endpointUrl\": \"https://example.com/webhooks/balance\",\n  \"eventTypes\": [\n    \"balance.extracted\"\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.fynapse.com/api/v1/event-deliveries/subscriptions', [
  'body' => '{
  "name": "Balance Webhook",
  "endpointUrl": "https://example.com/webhooks/balance",
  "eventTypes": [
    "balance.extracted"
  ]
}',
  'headers' => [
    'Authorization' => '<token>.',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.fynapse.com/api/v1/event-deliveries/subscriptions");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<token>.");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Balance Webhook\",\n  \"endpointUrl\": \"https://example.com/webhooks/balance\",\n  \"eventTypes\": [\n    \"balance.extracted\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<token>.",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Balance Webhook",
  "endpointUrl": "https://example.com/webhooks/balance",
  "eventTypes": ["balance.extracted"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.fynapse.com/api/v1/event-deliveries/subscriptions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

Here you will need to provide:

### Schema (`request`)

```yaml
openapi: 3.1.0
info:
  title: API
  version: 1.0.0
paths:
  /api/v1/event-deliveries/subscriptions:
    post:
      operationId: subpackageEventsSubscriptions_create
      summary: Create subscription
      description: >-
        This endpoint creates a new webhook subscription. When another write to
        the same name is in progress, it returns 409 `WriteInProgress`; retry.
      tags:
        - subpackage_events/subscriptions
      responses:
        '201':
          description: Successfully created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubscriptionResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/schema.Error'
        '401':
          description: Authentication Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/schema.Error'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/schema.Error'
        '429':
          description: Too many requests. Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/schema.Error'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/schema.Error'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubscriptionRequest'
tags:
  - name: subpackage_events/subscriptions
servers:
  - url: https://api.fynapse.com
    description: Production
components:
  schemas:
    SubscriptionRequest:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 255
          description: Unique name of the subscription
        endpointUrl:
          type: string
          minLength: 1
          description: Target URL for the webhook delivery
        secretRef:
          type:
            - string
            - 'null'
          description: >-
            Reference name of the secret to use for signing. If omitted on
            create, a secret is auto-created with the subscription name.
        eventTypes:
          type: array
          items:
            type: string
            minLength: 1
          description: List of event types to subscribe to. At least one type is required.
        description:
          type: string
          maxLength: 1024
          description: Optional description
      required:
        - name
        - endpointUrl
        - eventTypes
      description: Request to create or update a webhook subscription
      title: SubscriptionRequest
    SubscriptionResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Unique ID of the subscription
        name:
          type: string
          description: Unique name of the subscription
        endpointUrl:
          type: string
          description: Target URL for the webhook delivery
        secretRef:
          type: string
          description: Reference name of the secret used for signing
        eventTypes:
          type: array
          items:
            type: string
          description: >-
            List of event types subscribed to. Always contains at least one
            type.
        isActive:
          type: boolean
          description: Whether the subscription is active
        description:
          type: string
          description: Optional description
        createdTime:
          type: string
          format: date-time
          description: Time when the subscription was created
        updatedTime:
          type: string
          format: date-time
          description: Time when the subscription was last updated
        createdBy:
          type: string
          description: Username of the user who created the subscription
        updatedBy:
          type: string
          description: Username of the user who last updated the subscription
        secretValue:
          type:
            - string
            - 'null'
          description: >-
            Plaintext secret value. Populated on create and when fetching a
            subscription by ID.
      description: Response containing webhook subscription details
      title: SubscriptionResponse
    schema.ErrorItem:
      type: object
      properties:
        title:
          type: string
        detail:
          type: string
        type:
          type: string
        path:
          type: string
        args:
          type: object
          additionalProperties:
            type: string
      required:
        - title
        - detail
        - type
        - path
        - args
      title: schema.ErrorItem
    schema.Error:
      type: object
      properties:
        title:
          type: string
        detail:
          type: string
        type:
          type: string
        path:
          type: string
        args:
          type: object
          additionalProperties:
            type: string
        timestamp:
          type: string
          format: date-time
        reference:
          type: string
          format: uuid
        status:
          type: integer
        instance:
          type: string
        errors:
          type: array
          items:
            $ref: '#/components/schemas/schema.ErrorItem'
      required:
        - title
        - detail
        - type
        - path
        - args
        - timestamp
        - reference
        - status
        - instance
        - errors
      title: schema.Error

```

## Step 3 — Configure Your Receiver

Your webhook endpoint must:

* Accept POST requests
* Accept application/json payloads
* Validate the webhook signature
* Handle duplicate deliveries using the `Idempotency-Key`

See:

* [Webhook Security](/api-reference/getting-started/webhooks/security)
* [Delivery & Retries](/api-reference/getting-started/webhooks/delivery-retries)

The list of available Event Types can be found [here](/api-reference/getting-started/webhooks/event-types)

## Testing the Integration

To verify your setup:

* Trigger a balance extract manually
* Confirm your endpoint receives the request
* Validate the signature
* Ensure the event is processed successfully

If the endpoint does not return `2xx`, the delivery will be retried automatically.

## Watch a Video about how Webhooks Operate