> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.truvo.com/llms.txt.

# Create an event subscription

POST https://api.truvo.com/v1/event-subscriptions
Content-Type: application/json

Reference: https://docs.truvo.com/api-reference/create-event-subscription

## Authentication

- `Authorization` header (bearer token, required) — Your Truvo API key, sent as a bearer token. The prefix selects sandbox (trv_sandbox_) or live (trv_live_).

## Request

### Headers

- `Truvo-Version` (enum, required, default: 2026-09-26) — The contract revision of this request, which every operation in this document requires. This document describes 2026-09-26. Served revisions: 2026-09-26. A missing header, or one that names no served revision exactly, answers `invalid_version` (400), and its field error lists the served revisions in `allowed_values`, newest first.
  - Allowed values: `2026-09-26`
- `Idempotency-Key` (string, required) — A caller-chosen request key. A key replays for at least 24 hours. The same key with the same body replays the first answer; the same key with a different body is a conflict.

### Body (application/json)

This endpoint expects a CreateEventSubscriptionHttpBody.

- `url` (string, required)
- `event_types` (list of enum, required)
  - Allowed values: `quote_request.queued`, `quote_request.updated`, `quote_request.completed`, `quote_request.failed`, `quote.created`, `quote.updated`, `quote.expired`, `purchase.updated`, `purchase.requires_action`, `purchase.completed`, `purchase.needs_review`, `purchase.failed`

## Response

### 200

Create a webhook subscription to exact event types, up to 10 for each integration. The answer carries the signing secret once.

- `id` (string, required)
- `environment` (string, required)
- `url` (string, required)
- `status` (enum, required)
  - Allowed values: `active`, `disabled`
- `event_types` (list of string, required) — The event types that the subscription receives. A create or a change names at least one. A subscription that named only a type that v1 no longer sends lists none.
- `signing_secret` (string, required, nullable)

## Errors

### 400 Bad Request Error

Error envelope. One of: invalid_version, invalid_json.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 401 Unauthorized Error

Error envelope. One of: authentication_failed.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 403 Forbidden Error

Error envelope. One of: forbidden.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 409 Conflict Error

Error envelope. One of: conflict.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 413 Content Too Large Error

Error envelope. One of: request_too_large.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 422 Unprocessable Entity Error

Error envelope. One of: invalid_input.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 429 Too Many Requests Error

Error envelope. One of: rate_limited.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 500 Internal Server Error

Error envelope. One of: internal_error.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

### 503 Service Unavailable Error

Error envelope. One of: service_unavailable.

- `error` (ErrorEnvelopeError, required)
- `request_id` (string, required)

## Types

### ErrorEnvelopeError

- `code` (string, required)
- `message` (string, required)
- `field_errors` (list of FieldError, required, nullable)
- `retry_action` (RetryAction, required)
- `doc_url` (string, required)

### FieldError

- `path` (string, required)
- `message` (string, required)
- `allowed_values` (list of string, optional)

### RetryAction

- `type` (enum, required)
  - Allowed values: `none`, `retry`, `correct_input`, `supply_facts`, `read_status`, `use_new_request_key`, `wait`, `contact_support`
- `summary` (string, required)

## Examples

**Request**

```json
{
  "url": "https://hooks.example.com/truvo",
  "event_types": [
    "quote_request.completed",
    "quote_request.failed"
  ]
}
```

**Response**

```json
{
  "id": "sub_53e3e36ac096b9d2e3cad557691d523f",
  "environment": "sandbox",
  "url": "https://hooks.example.com/truvo",
  "status": "active",
  "event_types": [
    "quote_request.completed",
    "quote_request.failed"
  ],
  "signing_secret": "whsec_gI0Fd9cR3ZG0YatcULcNZvGiqCHu8WVHh6GcrYzhjDQ="
}
```

**SDK Code**

```python Completed and failed requests
import requests

url = "https://api.truvo.com/v1/event-subscriptions"

payload = {
    "url": "https://hooks.example.com/truvo",
    "event_types": ["quote_request.completed", "quote_request.failed"]
}
headers = {
    "Idempotency-Key": "bc950ff9-22ca-425c-9c9b-b8f9ccc8b26e",
    "Truvo-Version": "2026-09-26",
    "Authorization": "Bearer <apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Completed and failed requests
const url = 'https://api.truvo.com/v1/event-subscriptions';
const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': 'bc950ff9-22ca-425c-9c9b-b8f9ccc8b26e',
    'Truvo-Version': '2026-09-26',
    Authorization: 'Bearer <apiKey>',
    'Content-Type': 'application/json'
  },
  body: '{"url":"https://hooks.example.com/truvo","event_types":["quote_request.completed","quote_request.failed"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Completed and failed requests
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.truvo.com/v1/event-subscriptions"

	payload := strings.NewReader("{\n  \"url\": \"https://hooks.example.com/truvo\",\n  \"event_types\": [\n    \"quote_request.completed\",\n    \"quote_request.failed\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Idempotency-Key", "bc950ff9-22ca-425c-9c9b-b8f9ccc8b26e")
	req.Header.Add("Truvo-Version", "2026-09-26")
	req.Header.Add("Authorization", "Bearer <apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Completed and failed requests
require 'uri'
require 'net/http'

url = URI("https://api.truvo.com/v1/event-subscriptions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = 'bc950ff9-22ca-425c-9c9b-b8f9ccc8b26e'
request["Truvo-Version"] = '2026-09-26'
request["Authorization"] = 'Bearer <apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"url\": \"https://hooks.example.com/truvo\",\n  \"event_types\": [\n    \"quote_request.completed\",\n    \"quote_request.failed\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java Completed and failed requests
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.truvo.com/v1/event-subscriptions")
  .header("Idempotency-Key", "bc950ff9-22ca-425c-9c9b-b8f9ccc8b26e")
  .header("Truvo-Version", "2026-09-26")
  .header("Authorization", "Bearer <apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"url\": \"https://hooks.example.com/truvo\",\n  \"event_types\": [\n    \"quote_request.completed\",\n    \"quote_request.failed\"\n  ]\n}")
  .asString();
```

```php Completed and failed requests
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.truvo.com/v1/event-subscriptions', [
  'body' => '{
  "url": "https://hooks.example.com/truvo",
  "event_types": [
    "quote_request.completed",
    "quote_request.failed"
  ]
}',
  'headers' => [
    'Authorization' => 'Bearer <apiKey>',
    'Content-Type' => 'application/json',
    'Idempotency-Key' => 'bc950ff9-22ca-425c-9c9b-b8f9ccc8b26e',
    'Truvo-Version' => '2026-09-26',
  ],
]);

echo $response->getBody();
```

```csharp Completed and failed requests
using RestSharp;

var client = new RestClient("https://api.truvo.com/v1/event-subscriptions");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "bc950ff9-22ca-425c-9c9b-b8f9ccc8b26e");
request.AddHeader("Truvo-Version", "2026-09-26");
request.AddHeader("Authorization", "Bearer <apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"url\": \"https://hooks.example.com/truvo\",\n  \"event_types\": [\n    \"quote_request.completed\",\n    \"quote_request.failed\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Completed and failed requests
import Foundation

let headers = [
  "Idempotency-Key": "bc950ff9-22ca-425c-9c9b-b8f9ccc8b26e",
  "Truvo-Version": "2026-09-26",
  "Authorization": "Bearer <apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "url": "https://hooks.example.com/truvo",
  "event_types": ["quote_request.completed", "quote_request.failed"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.truvo.com/v1/event-subscriptions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```