# Send a test of a broadcast (/docs/api-reference/broadcasts/test-broadcast)

Sends its content to up to 5 addresses as ordinary marketing emails (subject prefixed `[Test]`), filled with `contact`'s values or the fallbacks. They count like any send.

`POST https://api.coss.com/v1/broadcasts/{id}/test`

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 broadcast's id.

## Request body

- `to` (string[], required, 1-5 items): Who gets the test, at most 5 addresses.
- `contact` (string): A contact (id or address) whose values fill the template; default: fallbacks.

## 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.email.broadcasts.test("bcast_01k7c8m4q2f3e9v6t5r1n0p8yz", {
  to: [
    "me@acme.com",
  ],
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/broadcasts/bcast_01k7c8m4q2f3e9v6t5r1n0p8yz/test" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "to": [
    "me@acme.com"
  ]
}'
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.email.broadcasts.test(
    id="bcast_01k7c8m4q2f3e9v6t5r1n0p8yz",
    to=[
        "me@acme.com"
    ],
)
```

Go:

```go
import (
	"context"

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

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

request := &email.TestBroadcastRequest{
    ID: "bcast_01k7c8m4q2f3e9v6t5r1n0p8yz",
    To: []string{
        "me@acme.com",
    },
}
client.Email.Broadcasts.Test(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

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

client.email.broadcasts.test(
  id: "bcast_01k7c8m4q2f3e9v6t5r1n0p8yz",
  to: ["me@acme.com"]
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Email\Broadcasts\Requests\TestBroadcastRequest;

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

$client->email->broadcasts->test(
    'bcast_01k7c8m4q2f3e9v6t5r1n0p8yz',
    new TestBroadcastRequest([
        'to' => [
            'me@acme.com',
        ],
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.email.broadcasts.requests.TestBroadcastRequest;
import java.util.Arrays;

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

client.email().broadcasts().test(
    "bcast_01k7c8m4q2f3e9v6t5r1n0p8yz",
    TestBroadcastRequest
        .builder()
        .to(
            Arrays.asList("me@acme.com")
        )
        .build()
);
```

.NET:

```csharp
using Coss;
using Coss.Email;

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

await client.Email.Broadcasts.TestAsync(
    new TestBroadcastRequest
    {
        Id = "bcast_01k7c8m4q2f3e9v6t5r1n0p8yz",
        To = new List<string>() { "me@acme.com" },
    }
);
```

## Response 200

The test emails.

- `object` ("broadcast_test", required)
- `email_ids` (string[], required): The ids of the test emails.

Example:

```json
{
  "object": "broadcast_test",
  "email_ids": [
    "email_01k7c8m4q2f3e9v6t5r1n0p8yz"
  ]
}
```

## 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 broadcast with this id exists in the API key's environment (`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, or the emails can't be sent (e.g. `mailing_address_required`, `domain_not_verified`).
- `429`: The API key's send rate limit (`rate_limited`) or the send quota (`quota_exceeded`) is used up.
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).