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

# Create a webhook endpoint

POST https://api.pensar.dev/webhook-endpoints
Content-Type: application/json

Registers an endpoint and mints its signing secret, which this response returns once. Store it: it cannot be read back, and rotating means deleting and re-creating the endpoint. Duplicate `events` are collapsed. A URL Pensar would refuse to deliver to is a `400`; a URL already registered is a `409`.

Requires the `settings:write` API key scope.

Reference: https://docs.pensar.dev/api/api-reference/webhook-endpoints/create-webhook-endpoint

## Authentication

- `Authorization` header (bearer token, required) — A workspace API key, sent as `Authorization: Bearer`.
- `x-api-key` header (required) — A workspace API key, sent as `x-api-key`.

## Request

### Body (application/json)

This endpoint expects a CreateWebhookEndpointRequest.

- `url` (string, required) — HTTPS URL with a hostname that resolves only to public addresses. Unique within the workspace.
- `events` (list of enum, required)
  - Allowed values: `issue.created`, `issue.updated`, `issue.status_changed`, `retest.completed`, `pentest.completed`
- `description` (string, optional, nullable)
- `enabled` (boolean, optional) — Defaults to `true`.

## Response

### 201

The endpoint and its signing secret.

- `endpoint` (WebhookEndpoint, required)
- `secret` (string, required) — Signing secret. Returned only here; it cannot be read back later.

## Errors

### 400 Bad Request Error

The request is invalid. `error` names the field.

- `error` (string, required) — What went wrong, naming the offending value when useful.

### 401 Unauthorized Error

The API key is missing or invalid.

- `error` (string, required) — What went wrong, naming the offending value when useful.

### 403 Forbidden Error

The credential lacks the required scope or is not allowed this action.

- `error` (string, required) — What went wrong, naming the offending value when useful.

### 409 Conflict Error

The request conflicts with the current state of the resource.

- `error` (string, required) — What went wrong, naming the offending value when useful.

## Types

### WebhookEndpoint

- `id` (string, required)
- `url` (string, required)
- `events` (list of enum, required)
  - Allowed values: `issue.created`, `issue.updated`, `issue.status_changed`, `retest.completed`, `pentest.completed`
- `enabled` (boolean, required)
- `description` (string, required, nullable)
- `health` (WebhookEndpointHealth, required) — Updated on every delivery attempt.
- `createdAt` (datetime, required)
- `updatedAt` (datetime, required)

### WebhookEndpointHealth

Updated on every delivery attempt.

- `lastAttemptAt` (datetime, required, nullable)
- `lastStatus` (enum, required, nullable)
  - Allowed values: `success`, `failed`
- `lastResponseCode` (integer, required, nullable)
- `consecutiveFailures` (integer, required) — Reset on success. At 20 the endpoint is disabled.

## Examples

**Request**

```json
{
  "url": "https://hooks.acme.example/pensar",
  "events": [
    "issue.created"
  ]
}
```

**Response**

```json
{
  "endpoint": {
    "id": "string",
    "url": "https://hooks.acme.example/pensar",
    "events": [
      "issue.created"
    ],
    "enabled": true,
    "description": "string",
    "health": {
      "lastAttemptAt": "2024-01-15T09:30:00Z",
      "lastStatus": "success",
      "lastResponseCode": 1,
      "consecutiveFailures": 1
    },
    "createdAt": "2024-01-15T09:30:00Z",
    "updatedAt": "2024-01-15T09:30:00Z"
  },
  "secret": "whsec_2f1c9a7e"
}
```

**SDK Code**

```python
import requests

url = "https://api.pensar.dev/webhook-endpoints"

payload = {
    "url": "https://hooks.acme.example/pensar",
    "events": ["issue.created"]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.pensar.dev/webhook-endpoints';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"url":"https://hooks.acme.example/pensar","events":["issue.created"]}'
};

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.pensar.dev/webhook-endpoints"

	payload := strings.NewReader("{\n  \"url\": \"https://hooks.acme.example/pensar\",\n  \"events\": [\n    \"issue.created\"\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
require 'uri'
require 'net/http'

url = URI("https://api.pensar.dev/webhook-endpoints")

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://hooks.acme.example/pensar\",\n  \"events\": [\n    \"issue.created\"\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.pensar.dev/webhook-endpoints")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"url\": \"https://hooks.acme.example/pensar\",\n  \"events\": [\n    \"issue.created\"\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.pensar.dev/webhook-endpoints', [
  'body' => '{
  "url": "https://hooks.acme.example/pensar",
  "events": [
    "issue.created"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.pensar.dev/webhook-endpoints");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"url\": \"https://hooks.acme.example/pensar\",\n  \"events\": [\n    \"issue.created\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "url": "https://hooks.acme.example/pensar",
  "events": ["issue.created"]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.pensar.dev/webhook-endpoints")! 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()
```