Send a synthetic request to a pre-call hook
POST /v1/pre-call-hooks/{hook_id}/test
| Property | Value |
|---|---|
| Operation | test_pre_call_hook |
| Group | Pre-call hooks |
| Scope | hooks:write |
| Route class | control |
| Idempotency | Idempotency-Key accepted: a retry with the same key replays the first answer |
| Audit | Audited dispatch.pre_call_hook.test (mutation) |
| Released in | 1.52.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Sends one synthetic request through the production path (1.52.0): signed, through the egress guard, with livemode false and a synthetic Call, caller and number, whatever the status of the hook. Answers what it came to, names and codes only; a failure is an outcome, not an error. It writes an Audit event, never the response.
Request
Set VOCAL_API to the base URL of your API and VOCAL_API_KEY to an API key with the hooks:write scope (Authentication and keys). Replace each placeholder, such as agt_... or <name>, with your own value.
curl -X POST "$VOCAL_API/v1/pre-call-hooks/pch_.../test" \
-H "Authorization: Bearer $VOCAL_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{}'const response = await fetch(`${process.env.VOCAL_API}/v1/pre-call-hooks/pch_.../test`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VOCAL_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
});
console.log(response.status, await response.text());import os
import uuid
import requests
response = requests.post(
f"{os.environ['VOCAL_API']}/v1/pre-call-hooks/pch_.../test",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={},
)
print(response.status_code, response.text)Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
hook_id | path | PreCallHookId | yes | The id of a pre-call hook: pch_ and the row's UUIDv7 in 26 Crockford base32 characters. Opaque and safe to log. |
idempotency-key | header | string | no | A client-chosen key, kept 24 hours per Organization, environment and route. A replay returns the stored response. |
Request body
Content type application/json, required: PreCallHookTestRequest.
| Field | Type | Required | Description |
|---|---|---|---|
direction | one of "inbound", "outbound", "web", "app" | no | The kind of Call the synthetic request describes; inbound when omitted. |
Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
200 | application/json | PreCallHookTestResult | |
400 | application/json | ErrorEnvelope | invalid_request |
401 | application/json | ErrorEnvelope | unauthenticated |
403 | application/json | ErrorEnvelope | forbidden, org_suspended |
404 | application/json | ErrorEnvelope | not_found |
409 | application/json | ErrorEnvelope | idempotency_in_progress, idempotency_key_reused |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 200 answer
The shape is PreCallHookTestResult.
| Field | Type | Required | Description |
|---|---|---|---|
compliance_changes | array of PreCallComplianceField | no | The fields of compliance the answer applied (1.54.0), each under /compliance; empty when it tightened nothing. Absent from an api before 1.54.0. |
decline_reason | string or null | yes | |
failure_code | PreCallFailureCode or null | yes | |
http_status | integer or null | yes | |
latency_ms | integer | yes | |
object | "pre_call_hook_test" | yes | |
outcome | PreCallOutcome | yes | |
overridden_settings | array of string | yes | The paths of the settings it overrode. |
request_id | PreCallRequestId | yes | |
selected_agent | PreCallAgentVersion or null | yes | |
tags | array of CallTag | yes | |
variables_set | array of string | yes | The names of the variables it supplied. |
violations | array of PreCallViolation | yes | The JSON path and code of each value outside the bounds, never the value. |