# Send a message (/docs/api-reference/hooks-messages/send-hook-message)

Queues a message to the application: coss.com delivers it to each of its enabled endpoints subscribed to `event_type` within seconds, signed with each endpoint's secret, and retries failures with backoff for about a day. Each request's `webhook-id` header is the message's id. Counts against the send quota once per endpoint it goes to (at least once). A live message is billed once, whatever its fan-out; retries and sandbox are free. Live sends are refused while the organization is suspended (`account_suspended`), on a billing hold (`billing_hold`), over a budget (`budget_exceeded`) or past Free's monthly messages (`usage_limit_exceeded`). Hooks resources belong to the API key's own environment: a `coss_test_…` key only ever sees sandbox ones, a `coss_live_…` key only production ones.

`POST https://api.coss.com/v1/hooks/applications/{application}/messages`

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

- `application` (string, required): The application's `id` (`happ_…`) or your `uid` for it.

## Headers

- `Idempotency-Key` (string, 1-256 characters): Makes retries safe: a repeated request with the same key and body returns the original message instead of sending again, for 24 hours. 1-256 characters.

## Request body

- `event_type` (string, required): What happened, e.g. `invoice.paid`. Endpoints that filter by type only get the types they chose. The type doesn't have to be registered.
- `payload` (map of any, required): The JSON object delivered as the request body (at most 256 KB serialized). It is parsed and serialized again: send integers beyond 2^53 as strings.

## 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.hooks.messages.send({
  application: "customer_8812",
  event_type: "invoice.paid",
  payload: {
    invoice_id: "in_1042",
    amount: 4200,
    currency: "usd",
  },
}, {
  idempotencyKey: "invoice-1042-paid",
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/hooks/applications/customer_8812/messages" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Idempotency-Key: invoice-1042-paid" \
  -H "Content-Type: application/json" \
  -d '{
  "event_type": "invoice.paid",
  "payload": {
    "invoice_id": "in_1042",
    "amount": 4200,
    "currency": "usd"
  }
}'
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.hooks.messages.send(
    application="customer_8812",
    idempotency_key="invoice-1042-paid",
    event_type="invoice.paid",
    payload={
        "invoice_id": "in_1042",
        "amount": 4200,
        "currency": "usd"
    },
)
```

Go:

```go
import (
	"context"

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

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

request := &hooks.SendHookMessageRequest{
    Application: "customer_8812",
    IdempotencyKey: coss.String(
        "invoice-1042-paid",
    ),
    EventType: "invoice.paid",
    Payload: map[string]any{
        "amount": 4200,
        "currency": "usd",
        "invoice_id": "in_1042",
    },
}
client.Hooks.Messages.Send(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

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

client.hooks.messages.send_(
  application: "customer_8812",
  idempotency_key: "invoice-1042-paid",
  event_type: "invoice.paid",
  payload: {
    invoice_id: "in_1042",
    amount: 4200,
    currency: "usd"
  }
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Hooks\Messages\Requests\SendHookMessageRequest;

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

$client->hooks->messages->send(
    'customer_8812',
    new SendHookMessageRequest([
        'idempotencyKey' => 'invoice-1042-paid',
        'eventType' => 'invoice.paid',
        'payload' => [
            'invoice_id' => "in_1042",
            'amount' => 4200,
            'currency' => "usd",
        ],
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.hooks.messages.requests.SendHookMessageRequest;
import java.util.HashMap;

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

client.hooks().messages().send(
    "customer_8812",
    SendHookMessageRequest
        .builder()
        .eventType("invoice.paid")
        .idempotencyKey("invoice-1042-paid")
        .payload(
            new HashMap<String, Object>() {{
                put("invoice_id", "in_1042");
                put("amount", 4200);
                put("currency", "usd");
            }}
        )
        .build()
);
```

.NET:

```csharp
using Coss;
using Coss.Hooks;

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

await client.Hooks.Messages.SendAsync(
    new SendHookMessageRequest
    {
        Application = "customer_8812",
        IdempotencyKey = "invoice-1042-paid",
        EventType = "invoice.paid",
        Payload = new Dictionary<string, object?>()
        {
            { "invoice_id", "in_1042" },
            { "amount", 4200 },
            { "currency", "usd" },
        },
    }
);
```

## Response 202

The message, queued for delivery.

- `object` ("hook_message", required)
- `id` (string, required): Also the `webhook-id` header of every request delivering it.
- `application_id` (string, required): The id of the application it was sent to.
- `event_type` (string, required): The event type it was sent as.
- `payload` (map of any, required): The JSON body delivered to each endpoint.
- `created_at` (string, required, date-time)

Example:

```json
{
  "object": "hook_message",
  "id": "hmsg_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "application_id": "happ_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "event_type": "invoice.paid",
  "payload": {
    "invoice_id": "in_1042",
    "amount": 4200,
    "currency": "usd"
  },
  "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`).
- `402`: The plan or the account's billing stands in the way of this live send: Free's monthly messages are used up (`usage_limit_exceeded`), an invoice is overdue or the spend or credit limit was reached (`billing_hold`), or a budget is spent (`budget_exceeded`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `404`: No application with this id or uid exists in the API key's environment (`application_not_found`).
- `409`: A request with this Idempotency-Key is still in progress (`request_in_progress`); retry.
- `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`), the payload is larger than 256 KB (`payload_too_large`), or the Idempotency-Key was used with another body (`idempotency_key_reused`).
- `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`).