# Poll a webhook listener (/docs/api-reference/webhook-endpoints/poll-webhook-listener)

Acknowledges deliveries handed out earlier, keeps the listener open for another 10 minutes, and waits up to `wait_ms` (at most 25 s) for events. Deliveries come oldest first; one not acknowledged within two minutes is handed out again (with the same `event_id`). The answer may come early, with no deliveries, when the API restarts: poll again. Polls are not request-logged; each acknowledgement is logged as a `webhook.forward` line.

`POST https://api.coss.com/v1/webhook_listeners/{id}/poll`

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).

## Path parameters

- `id` (string, required): The webhook listener's id.

## Request body

- `acks` (object[], at most 50 items): What happened to deliveries handed out earlier. A delivery is finished once acknowledged: a 2xx status (or none, with no error) succeeds; anything else fails. Neither is retried.
  - `delivery_id` (string, required)
  - `ack_token` (string, required, at most 64 characters): The delivery's `ack_token`.
  - `status_code` (integer | null, required, 100-599): What the local URL answered; `null` when nothing answered, or when the event was only printed.
  - `duration_ms` (integer, required, 0-3600000)
  - `error` (string | null, required, at most 500 characters): Why forwarding failed (e.g. `connection refused`); `null` if it didn't.
- `wait_ms` (integer, 0-25000): How long to wait for deliveries when none is pending, in milliseconds. Default 20000, at most 25000.
- `limit` (integer, 1-50): The most deliveries to hand out. Default 10, at most 50.

## 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.poll("whlis_01k7c8m4q2f3e9v6t5r1n0p8yz", {
  acks: [
    {
      delivery_id: "whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv",
      ack_token: "mfz3k2a8",
      status_code: 200,
      duration_ms: 12,
      error: null,
    },
  ],
  wait_ms: 20000,
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/webhook_listeners/whlis_01k7c8m4q2f3e9v6t5r1n0p8yz/poll" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "acks": [
    {
      "delivery_id": "whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv",
      "ack_token": "mfz3k2a8",
      "status_code": 200,
      "duration_ms": 12,
      "error": null
    }
  ],
  "wait_ms": 20000
}'
```

Python:

```python
from coss import Coss
from coss import Coss, WebhookListenerAck

client = Coss()  # api_key= or COSS_API_KEY

client.webhook_listeners.poll(
    id="whlis_01k7c8m4q2f3e9v6t5r1n0p8yz",
    acks=[
        WebhookListenerAck(
            delivery_id="whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv",
            ack_token="mfz3k2a8",
            status_code=200,
            duration_ms=12,
            error=None,
        )
    ],
    wait_ms=20000,
)
```

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.PollWebhookListenerRequest{
    ID: "whlis_01k7c8m4q2f3e9v6t5r1n0p8yz",
    Acks: []*coss.WebhookListenerAck{
        &coss.WebhookListenerAck{
            DeliveryID: "whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv",
            AckToken: "mfz3k2a8",
            StatusCode: coss.Int(
                200,
            ),
            DurationMs: 12,
        },
    },
    WaitMs: coss.Int(
        20000,
    ),
}
client.WebhookListeners.Poll(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

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

client.webhook_listeners.poll(
  id: "whlis_01k7c8m4q2f3e9v6t5r1n0p8yz",
  acks: [{
    delivery_id: "whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv",
    ack_token: "mfz3k2a8",
    status_code: 200,
    duration_ms: 12,
    error: nil
  }],
  wait_ms: 20000
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Types\WebhookListenerAck;
use Coss\WebhookListeners\Requests\PollWebhookListenerRequest;

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

$client->webhookListeners->poll(
    'whlis_01k7c8m4q2f3e9v6t5r1n0p8yz',
    new PollWebhookListenerRequest([
        'acks' => [
            new WebhookListenerAck([
                'deliveryId' => 'whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv',
                'ackToken' => 'mfz3k2a8',
                'statusCode' => 200,
                'durationMs' => 12,
                'error' => null,
            ]),
        ],
        'waitMs' => 20000,
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.webhooklisteners.requests.PollWebhookListenerRequest;
import com.coss.types.WebhookListenerAck;
import java.util.Arrays;
import java.util.Optional;

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

client.webhookListeners().poll(
    "whlis_01k7c8m4q2f3e9v6t5r1n0p8yz",
    PollWebhookListenerRequest
        .builder()
        .acks(
            Optional.of(
                Arrays.asList(
                    WebhookListenerAck
                        .builder()
                        .deliveryId("whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv")
                        .ackToken("mfz3k2a8")
                        .durationMs(12)
                        .statusCode(
                            OptionalNullable.of(200)
                        )
                        .error(
                            Nullable.ofNull()
                        )
                        .build()
                )
            )
        )
        .waitMs(20000)
        .build()
);
```

.NET:

```csharp
using Coss;

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

await client.WebhookListeners.PollAsync(
    new PollWebhookListenerRequest
    {
        Id = "whlis_01k7c8m4q2f3e9v6t5r1n0p8yz",
        Acks = new List<WebhookListenerAck>()
        {
            new WebhookListenerAck
            {
                DeliveryId = "whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv",
                AckToken = "mfz3k2a8",
                StatusCode = 200,
                DurationMs = 12,
                Error = null,
            },
        },
        WaitMs = 20000,
    }
);
```

## Response 200

Deliveries to forward (possibly none).

- `object` ("webhook_listener_poll", required)
- `listener` (object, required)
  - `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)
- `deliveries` (object[], required): Events to forward, oldest first. Empty when none arrived while the poll waited. A delivery not acknowledged within two minutes is handed out again.
  - `object` ("webhook_listener_delivery", required)
  - `id` (string, required)
  - `ack_token` (string, required): Send it back with the delivery's acknowledgement in a later poll.
  - `event_id` (string, required): The event's id: the `id` of the body, and the `webhook-id` header endpoints receive.
  - `event_type` (string, required)
  - `attempt` (integer, required): How many polls have handed it out: more than 1 when an earlier answer was never acknowledged.
  - `body` (string, required): The event body, exactly as an endpoint with the listener's API version would receive it.
  - `created_at` (string, required, date-time)
- `acknowledged` (integer, required): How many of the request's acknowledgements were recorded.

Example:

```json
{
  "object": "webhook_listener_poll",
  "listener": {
    "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"
  },
  "deliveries": [
    {
      "object": "webhook_listener_delivery",
      "id": "whlisdel_01k7c8n2b5d7f9h1k3m5p7r9tv",
      "ack_token": "mfz3k2a8",
      "event_id": "evt_01k7c8n1z4c6e8g0j2l4n6q8sa",
      "event_type": "email.delivered",
      "attempt": 1,
      "body": "{\"id\":\"evt_01k7c8n1z4c6e8g0j2l4n6q8sa\",\"object\":\"event\",\"type\":\"email.delivered\",\"api_version\":\"2026-10-10\",\"created_at\":\"2026-01-15T09:30:00.000Z\",\"data\":{\"email_id\":\"email_01k7c8m9x3a5c7e9g1j3l5n7q9\",\"recipient\":\"user@example.com\"}}",
      "created_at": "2026-01-15T09:30:00.000Z"
    }
  ],
  "acknowledged": 0
}
```

## 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`).
- `404`: No open webhook listener with this id exists in the API key's environment: it was closed, or expired after 10 minutes without a poll (`not_found`).
- `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`).
- `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`).