# Create an event type (/docs/api-reference/hooks-event-types/create-hook-event-type)

Adds a type to the catalog your applications' users subscribe from (in the portal, or the `filter_types` of an endpoint), with a description, a JSON Schema and examples to show them. Messages can be sent with any type, registered or not. 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/event_types`

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

- `name` (string, required): The type's name, which messages send as `event_type`. Letters, digits and `. _ -`.
- `description` (string, at most 256 characters): What this event means, shown to your users.
- `schema` (map of any): A JSON Schema of the payload, shown to your users (not enforced).
- `examples` (map of any[], at most 5 items): Up to 5 example payloads; the first is what a test send delivers.

## 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.eventTypes.create({
  name: "invoice.paid",
  description: "An invoice was paid in full.",
  examples: [
    {
      invoice_id: "in_1042",
      amount: 4200,
      currency: "usd",
    },
  ],
});
```

HTTP:

```sh
curl -X POST "https://api.coss.com/v1/hooks/event_types" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "invoice.paid",
  "description": "An invoice was paid in full.",
  "examples": [
    {
      "invoice_id": "in_1042",
      "amount": 4200,
      "currency": "usd"
    }
  ]
}'
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.hooks.event_types.create(
    name="invoice.paid",
    description="An invoice was paid in full.",
    examples=[
        {
            "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.CreateHookEventTypeRequest{
    Name: "invoice.paid",
    Description: coss.String(
        "An invoice was paid in full.",
    ),
    Examples: []map[string]any{
        map[string]any{
            "amount": 4200,
            "currency": "usd",
            "invoice_id": "in_1042",
        },
    },
}
client.Hooks.EventTypes.Create(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

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

client.hooks.event_types.create(
  name: "invoice.paid",
  description: "An invoice was paid in full.",
  examples: [{
    invoice_id: "in_1042",
    amount: 4200,
    currency: "usd"
  }]
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Hooks\EventTypes\Requests\CreateHookEventTypeRequest;

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

$client->hooks->eventTypes->create(
    new CreateHookEventTypeRequest([
        'name' => 'invoice.paid',
        'description' => 'An invoice was paid in full.',
        'examples' => [
            [
                'invoice_id' => "in_1042",
                'amount' => 4200,
                'currency' => "usd",
            ],
        ],
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.hooks.eventtypes.requests.CreateHookEventTypeRequest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;

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

client.hooks().eventTypes().create(
    CreateHookEventTypeRequest
        .builder()
        .name("invoice.paid")
        .description("An invoice was paid in full.")
        .examples(
            Optional.of(
                Arrays.asList(
                    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.EventTypes.CreateAsync(
    new CreateHookEventTypeRequest
    {
        Name = "invoice.paid",
        Description = "An invoice was paid in full.",
        Examples = new List<Dictionary<string, object?>>()
        {
            new Dictionary<string, object?>()
            {
                { "invoice_id", "in_1042" },
                { "amount", 4200 },
                { "currency", "usd" },
            },
        },
    }
);
```

## Response 200

The event type.

- `object` ("hook_event_type", required)
- `name` (string, required): The type's name, which messages send as `event_type`.
- `description` (string | null, required): What this event means, shown to your users. `null`: none.
- `schema` (map of any | null, required): A JSON Schema of the payload, shown to your users (not enforced). `null`: none.
- `examples` (map of any[], required): Sample payloads, shown to your users. Test sends use the first.
- `archived` (boolean, required): Archived types are hidden from the portal and can't be subscribed to; messages of the type are still delivered to endpoints that subscribed before.
- `created_at` (string, required, date-time)
- `updated_at` (string, required, date-time)

Example:

```json
{
  "object": "hook_event_type",
  "name": "invoice.paid",
  "description": "An invoice was paid in full.",
  "schema": {
    "type": "object",
    "properties": {
      "invoice_id": {
        "type": "string"
      },
      "amount": {
        "type": "integer"
      }
    }
  },
  "examples": [
    {
      "invoice_id": "in_1042",
      "amount": 4200,
      "currency": "usd"
    }
  ],
  "archived": false,
  "created_at": "2026-01-15T09:30:00.000Z",
  "updated_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`), the type exists (`event_type_exists`), its schema and examples are larger than 64 KB (`payload_too_large`), or the environment has 1000 types (`too_many_event_types`).
- `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`).