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

# Create a webhook

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

Creates a webhook endpoint. Optional event_schemas may be supplied at creation time to customize `data.object` for supported event namespaces while preserving the normal webhook envelope.

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

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/json)

This endpoint expects an object.

- `url` (string, required) — Webhook endpoint URL
- `enabled_events` (list of string, required) — Array of event types to subscribe to, or ["*"] for all events
- `secret` (string, optional) — Secret for webhook signature verification
- `event_schemas` (list of WebhookCreateParamEventSchemasItem, optional) — Optional event schema overrides to create with the webhook. Event schemas customize only the delivered webhook payload's `data.object` for supported event namespaces. The webhook envelope fields are unchanged. After the webhook is created, manage event schemas through /v1/webhooks/\{webhook\_id}/event\_schemas.
- `oidc_auth_method` (enum, optional) — OIDC authentication method for obtaining access tokens. Required when configuring OIDC. 'private_key_jwt' — requires oidc_client_id, oidc_token_endpoint, oidc_access_token_ttl_seconds. 'client_secret' — requires oidc_client_id, oidc_client_secret, oidc_token_endpoint, oidc_access_token_ttl_seconds. Both methods optionally accept oidc_scope and oidc_resource_uri.
  - Allowed values: `private_key_jwt`, `client_secret`
- `oidc_client_id` (string, optional) — OIDC client ID. Required for both auth methods.
- `oidc_client_secret` (string, optional) — OIDC client secret. Required when oidc_auth_method is 'client_secret'. Write-only; never returned in responses.
- `oidc_token_endpoint` (string, optional) — OIDC token endpoint URL. Required for both auth methods.
- `oidc_resource_uri` (string, optional) — Optional. OIDC resource URI (Microsoft-specific; use oidc_scope for standard OAuth 2.0).
- `oidc_scope` (string, optional) — Optional. OAuth 2.0 scope for the token request (e.g. "api://\<app-id>/.default").
- `oidc_access_token_ttl_seconds` (integer, optional) — OIDC access token TTL in seconds. Required for both auth methods.

## Response

### 201

webhook created with wildcard events

- `any`

## Errors

### 422 Create Webhook Request Unprocessable Entity Error

invalid request

- `any`

## Types

### WebhookCreateParamEventSchemasItem

- `namespace` (string, required) — Event namespace for the schema override. Currently supported business event namespaces are business.created and business.updated.
- `schema` (string, required) — GraphQL selection set rooted at the event object for the namespace. For `business.updated`, select fields directly from the Business object. Use `snake_case` field names and omit an `object` wrapper.

## Examples

**Request**

```json
{
  "url": "https://example.com/webhooks/middesk",
  "enabled_events": [
    "business.created",
    "business.updated",
    "order.updated"
  ],
  "secret": "whsec_abcdef123456",
  "event_schemas": [
    {
      "namespace": "business.updated",
      "schema": "{ id name status }"
    }
  ]
}
```

**Response**

```json
{
  "created_at": "2025-01-07T12:00:00.000Z",
  "enabled_events": [
    "business.created",
    "business.updated",
    "order.updated"
  ],
  "event_schemas": [
    {
      "created_at": "2025-01-07T12:00:00.000Z",
      "id": "3f2a1c9e-8b4d-4e21-9c77-1a2b3c4d5e6f",
      "namespace": "business.updated",
      "object": "webhook_event_schema",
      "schema": "{ id name status }",
      "updated_at": "2025-01-07T12:00:00.000Z"
    }
  ],
  "id": "f2a3b4c5-d6e7-8901-5678-9abcdef01234",
  "object": "webhook",
  "updated_at": "2025-01-07T12:00:00.000Z",
  "url": "https://example.com/webhooks/middesk"
}
```

**SDK Code**

```python Webhook request
import requests

url = "https://api.middesk.com/v1/webhooks"

payload = {
    "url": "https://example.com/webhooks/middesk",
    "enabled_events": ["business.created", "business.updated", "order.updated"],
    "secret": "whsec_abcdef123456",
    "event_schemas": [
        {
            "namespace": "business.updated",
            "schema": "{ id name status }"
        }
    ]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Webhook request
const url = 'https://api.middesk.com/v1/webhooks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"url":"https://example.com/webhooks/middesk","enabled_events":["business.created","business.updated","order.updated"],"secret":"whsec_abcdef123456","event_schemas":[{"namespace":"business.updated","schema":"{ id name status }"}]}'
};

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

```go Webhook request
package main

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

func main() {

	url := "https://api.middesk.com/v1/webhooks"

	payload := strings.NewReader("{\n  \"url\": \"https://example.com/webhooks/middesk\",\n  \"enabled_events\": [\n    \"business.created\",\n    \"business.updated\",\n    \"order.updated\"\n  ],\n  \"secret\": \"whsec_abcdef123456\",\n  \"event_schemas\": [\n    {\n      \"namespace\": \"business.updated\",\n      \"schema\": \"{ id name status }\"\n    }\n  ]\n}")

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

	req.Header.Add("Authorization", "Bearer <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 Webhook request
require 'uri'
require 'net/http'

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

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"url\": \"https://example.com/webhooks/middesk\",\n  \"enabled_events\": [\n    \"business.created\",\n    \"business.updated\",\n    \"order.updated\"\n  ],\n  \"secret\": \"whsec_abcdef123456\",\n  \"event_schemas\": [\n    {\n      \"namespace\": \"business.updated\",\n      \"schema\": \"{ id name status }\"\n    }\n  ]\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.middesk.com/v1/webhooks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"url\": \"https://example.com/webhooks/middesk\",\n  \"enabled_events\": [\n    \"business.created\",\n    \"business.updated\",\n    \"order.updated\"\n  ],\n  \"secret\": \"whsec_abcdef123456\",\n  \"event_schemas\": [\n    {\n      \"namespace\": \"business.updated\",\n      \"schema\": \"{ id name status }\"\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.middesk.com/v1/webhooks', [
  'body' => '{
  "url": "https://example.com/webhooks/middesk",
  "enabled_events": [
    "business.created",
    "business.updated",
    "order.updated"
  ],
  "secret": "whsec_abcdef123456",
  "event_schemas": [
    {
      "namespace": "business.updated",
      "schema": "{ id name status }"
    }
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp Webhook request
using RestSharp;

var client = new RestClient("https://api.middesk.com/v1/webhooks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"url\": \"https://example.com/webhooks/middesk\",\n  \"enabled_events\": [\n    \"business.created\",\n    \"business.updated\",\n    \"order.updated\"\n  ],\n  \"secret\": \"whsec_abcdef123456\",\n  \"event_schemas\": [\n    {\n      \"namespace\": \"business.updated\",\n      \"schema\": \"{ id name status }\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Webhook request
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "url": "https://example.com/webhooks/middesk",
  "enabled_events": ["business.created", "business.updated", "order.updated"],
  "secret": "whsec_abcdef123456",
  "event_schemas": [
    [
      "namespace": "business.updated",
      "schema": "{ id name status }"
    ]
  ]
] as [String : Any]

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

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