# Create a webhook

### Create a webhook

`POST /api/v1/webhooks`

Operation ID: `createWebhook`

Each webhook gets the event types it asks for, every type by default, signed with that webhook's secret. Up to 5 per workspace. See [Webhooks](https://needle.app/docs/webhooks) for the request body, headers, signature checks, and retries.

**Request body** (required)

- `url` (string · uri, required): An https URL that accepts POST requests.
- `headers` (object, optional): Extra headers sent with every request, for example an API key your endpoint checks: {"Authorization": "Bearer ..."}. Up to 5. Names are stored in lower case.
- `eventTypes` (string | string[], optional): The event types this webhook gets: "all" (every type, also types added later) or a list. Left out, it is "all".

**201**: Webhook created. The response carries the secret.

- `webhook` (object, required)
  - `id` (string · uuid, required)
  - `url` (string, required)
  - `headerNames` (string[], required): Names of the extra headers sent with every request.
  - `eventTypes` (string | string[], required): The [event types](https://needle.app/docs/webhooks#event-types) this webhook gets. "all" means every type, also types added later. A list stays as it is: types added later are not sent until you add them.
  - `lastAttemptAt` (string · date-time | null, required)
  - `lastError` (string | null, required): Why the last failed delivery failed, for example 401. Null once a delivery succeeds.
  - `createdAt` (string · date-time, required)
  - `createdBy` (string · uuid, required): The member who created the webhook. It receives the events they can see, and is deleted when they leave the workspace.
- `secret` (string, required): The signing secret, whsec_…. Returned only here, when the webhook is created, and never again.
- `requestId` (string · uuid, required): Id of this request, for support and troubleshooting

**Errors**

- `400`: Bad request
- `401`: Unauthorized: missing or invalid API key
- `403`: Forbidden
- `404`: Not found
- `409`: The workspace already has 5 webhooks.
- `422`: Invalid request payload
