# Open a webhook listener (/docs/api-reference/webhook-endpoints/create-webhook-listener)

Listeners are how `coss listen` forwards events to a local server: coss.com can't reach `localhost`, so the CLI pulls them. They belong to the API key's environment, receive events created after they open, and don't count toward the plan's webhook endpoints. A listener closes when it is deleted or after 10 minutes without a poll; an environment has at most 5 open at once. Events reach it unsigned: the CLI signs what it forwards with its own secret.

`POST https://api.coss.com/v1/webhook_listeners`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Request body

- `event_types` (string[], at most 100 items): Event types to receive. Defaults to every event type.
- `api_version` ("2026-10-10"): The API version events are rendered in. Defaults to the version of the request that creates the listener.
- `description` (string | null, at most 256 characters): Where the events go, for your own reference (shown in the log).

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.webhookListeners.create({
  event_types: [
    "email.sent",
    "email.delivered",
  ],
  description: "localhost:3000/webhooks",
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/webhook_listeners" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "event_types": [
    "email.sent",
    "email.delivered"
  ],
  "description": "localhost:3000/webhooks"
}'
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.webhook_listeners.create(
    event_types=[
        "email.sent",
        "email.delivered"
    ],
    description="localhost:3000/webhooks",
)
```

Go:

```go
import (
	"context"

	coss "github.com/cosscom/coss-go"
	cossclient "github.com/cosscom/coss-go/client"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &coss.CreateWebhookListenerRequest{
    EventTypes: []coss.CreateWebhookListenerRequestEventTypesItem{
        coss.CreateWebhookListenerRequestEventTypesItemEmailSent,
        coss.CreateWebhookListenerRequestEventTypesItemEmailDelivered,
    },
    Description: coss.String(
        "localhost:3000/webhooks",
    ),
}
client.WebhookListeners.Create(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.webhook_listeners.create(
  event_types: %w[email.sent email.delivered],
  description: "localhost:3000/webhooks"
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\WebhookListeners\Requests\CreateWebhookListenerRequest;
use Coss\WebhookListeners\Types\CreateWebhookListenerRequestEventTypesItem;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->webhookListeners->create(
    new CreateWebhookListenerRequest([
        'eventTypes' => [
            CreateWebhookListenerRequestEventTypesItem::EmailSent->value,
            CreateWebhookListenerRequestEventTypesItem::EmailDelivered->value,
        ],
        'description' => 'localhost:3000/webhooks',
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.webhooklisteners.requests.CreateWebhookListenerRequest;
import com.coss.resources.webhooklisteners.types.CreateWebhookListenerRequestEventTypesItem;
import java.util.Arrays;
import java.util.Optional;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.webhookListeners().create(
    CreateWebhookListenerRequest
        .builder()
        .description(
            OptionalNullable.of("localhost:3000/webhooks")
        )
        .eventTypes(
            Optional.of(
                Arrays.asList(CreateWebhookListenerRequestEventTypesItem.EMAIL_SENT, CreateWebhookListenerRequestEventTypesItem.EMAIL_DELIVERED)
            )
        )
        .build()
);
```

.NET:

```csharp
using Coss;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.WebhookListeners.CreateAsync(
    new CreateWebhookListenerRequest
    {
        EventTypes = new List<CreateWebhookListenerRequestEventTypesItem>()
        {
            CreateWebhookListenerRequestEventTypesItem.EmailSent,
            CreateWebhookListenerRequestEventTypesItem.EmailDelivered,
        },
        Description = "localhost:3000/webhooks",
    }
);
```

## Response 200

The listener.

- `object` ("webhook_listener", required)
- `id` (string, required)
- `api_version` (string, required): The API version (`Coss-Version`) the listener's events are rendered in.
- `event_types` (string[], required): Event types the listener receives. An empty array means every event type.
- `description` (string | null, required): Your note about it, such as the machine it's on. `null`: none.
- `expires_at` (string, required, date-time): When the listener closes unless it is polled again; every poll moves it 10 minutes ahead.
- `created_at` (string, required, date-time)

Example:

```json
{
  "object": "webhook_listener",
  "id": "whlis_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "api_version": "2026-10-10",
  "event_types": [
    "email.delivered",
    "email.bounced"
  ],
  "description": "bailey-mbp → localhost:3000/webhooks",
  "expires_at": "2026-01-15T09:40:00.000Z",
  "created_at": "2026-01-15T09:30:00.000Z"
}
```

## Errors

- `400`: The body is not valid JSON (`invalid_json`). Also when the `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `413`: The request body is larger than 5 MB (`payload_too_large`).
- `415`: The body is not sent as `application/json` (`unsupported_media_type`).
- `422`: The body failed validation (`validation_error`, including an unknown `api_version`), or the environment already has 5 open listeners (`too_many_listeners`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).