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

# Create webhook configuration

POST https://api.useroot.com/api/webhooks
Content-Type: application/json

Creates a new webhook configuration for the entity. The generated secret key is returned only in this initial response and should be stored securely.

Reference: https://useroot.docs.buildwithfern.com/api-reference/webhooks-api/create-webhook

## Authentication

- `x-api-key` header (required) — RootPay API key sent in the x-api-key header. Keys are environment-scoped: live_* for production, test_* for sandbox.

## Request

### Body (application/json)

- `url` (string, required)
- `event_types` (list of enum, required) — Non-empty allowlist of subscribed webhook event types. Persisted as NOT NULL on webhook_configs (see migration backfill).
  - Allowed values: `payout.debited`, `payout.settled`, `payout.failed`, `payin.settled`, `payin.failed`, `subaccount.credit_received`
- `description` (string, optional, nullable)

## Response

### 201

Webhook configuration created successfully

- `data` (object, required) — Response model for webhook creation that includes the secret key.
  - `created_at` (datetime, required)
  - `updated_at` (datetime, required)
  - `id` (string, required)
  - `url` (string, required)
  - `description` (string, required, nullable)
  - `is_active` (boolean, required)
  - `event_types` (list of string, required) — Sorted allowlist of subscribed webhook event types
  - `secret_key` (string, required)
- `warning` (string, optional, nullable)

## Examples

**Request**

```json
{
  "url": "https://example.com/webhook",
  "event_types": [
    "payout.settled",
    "payout.failed",
    "payin.settled"
  ],
  "description": "Payment notifications webhook"
}
```

**Response**

```json
{
  "data": {
    "created_at": "2024-03-20T12:00:00Z",
    "updated_at": "2024-03-20T12:00:00Z",
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "url": "https://example.com/webhook",
    "description": "Payment notifications webhook",
    "is_active": true,
    "event_types": [
      "payin.failed",
      "payin.settled",
      "payout.debited",
      "payout.failed",
      "payout.settled",
      "subaccount.credit_received"
    ],
    "secret_key": "verySecureRandomKeyThatIsLongEnough"
  }
}
```

**SDK Code**

```python Create webhook configuration
import requests

url = "https://api.useroot.com/api/webhooks"

payload = {
    "url": "https://example.com/webhook",
    "event_types": ["payout.settled", "payout.failed", "payin.settled"],
    "description": "Payment notifications webhook"
}
headers = {
    "x-api-key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Create webhook configuration
const url = 'https://api.useroot.com/api/webhooks';
const options = {
  method: 'POST',
  headers: {'x-api-key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"url":"https://example.com/webhook","event_types":["payout.settled","payout.failed","payin.settled"],"description":"Payment notifications webhook"}'
};

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

```go Create webhook configuration
package main

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

func main() {

	url := "https://api.useroot.com/api/webhooks"

	payload := strings.NewReader("{\n  \"url\": \"https://example.com/webhook\",\n  \"event_types\": [\n    \"payout.settled\",\n    \"payout.failed\",\n    \"payin.settled\"\n  ],\n  \"description\": \"Payment notifications webhook\"\n}")

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

	req.Header.Add("x-api-key", "<apiKey>")
	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 Create webhook configuration
require 'uri'
require 'net/http'

url = URI("https://api.useroot.com/api/webhooks")

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

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"url\": \"https://example.com/webhook\",\n  \"event_types\": [\n    \"payout.settled\",\n    \"payout.failed\",\n    \"payin.settled\"\n  ],\n  \"description\": \"Payment notifications webhook\"\n}"

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

```java Create webhook configuration
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.useroot.com/api/webhooks")
  .header("x-api-key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"url\": \"https://example.com/webhook\",\n  \"event_types\": [\n    \"payout.settled\",\n    \"payout.failed\",\n    \"payin.settled\"\n  ],\n  \"description\": \"Payment notifications webhook\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.useroot.com/api/webhooks', [
  'body' => '{
  "url": "https://example.com/webhook",
  "event_types": [
    "payout.settled",
    "payout.failed",
    "payin.settled"
  ],
  "description": "Payment notifications webhook"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-api-key' => '<apiKey>',
  ],
]);

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

```csharp Create webhook configuration
using RestSharp;

var client = new RestClient("https://api.useroot.com/api/webhooks");
var request = new RestRequest(Method.POST);
request.AddHeader("x-api-key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"url\": \"https://example.com/webhook\",\n  \"event_types\": [\n    \"payout.settled\",\n    \"payout.failed\",\n    \"payin.settled\"\n  ],\n  \"description\": \"Payment notifications webhook\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create webhook configuration
import Foundation

let headers = [
  "x-api-key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "url": "https://example.com/webhook",
  "event_types": ["payout.settled", "payout.failed", "payin.settled"],
  "description": "Payment notifications webhook"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.useroot.com/api/webhooks")! 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()
```