Create a pre-call hook
POST /v1/pre-call-hooks
| Property | Value |
|---|---|
| Operation | create_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.create (mutation) |
| Released in | 1.52.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Creates a hook on a Phone number, an Agent or the Organization at revision 1 and answers its secret once (1.52.0). A scope that has a hook is pre_call_hook_scope_taken. In a PHI-mode Organization a hook is created paused unless attested, and status: active is phi_attestation_required. The URL passes the egress guard (egress_denied with its reason), and every issue is a detail of 422 validation_failed (PreCallHookIssueCode). A replay under the same Idempotency-Key creates nothing and answers secret null.
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" \
-H "Authorization: Bearer $VOCAL_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"scope": {
"type": "phone_number",
"id": "pn_..."
},
"url": "<url>",
"directions": [
"inbound"
]
}'const response = await fetch(`${process.env.VOCAL_API}/v1/pre-call-hooks`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.VOCAL_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
'Content-Type': 'application/json',
},
body: JSON.stringify({
"scope": {
"type": "phone_number",
"id": "pn_..."
},
"url": "<url>",
"directions": [
"inbound"
]
}),
});
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",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"scope": {
"type": "phone_number",
"id": "pn_...",
},
"url": "<url>",
"directions": [
"inbound",
],
},
)
print(response.status_code, response.text)Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
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: PreCallHookCreateRequest.
| Field | Type | Required | Description |
|---|---|---|---|
allowed_agent_ids | array of AgentId | no | |
default | PreCallHookAcceptInput or null | no | |
directions | array of PreCallHookDirection | yes | |
on_failure | PreCallHookOnFailure | no | |
scope | PreCallHookScope | yes | |
status | one of "active", "paused" | no | degraded is set by the platform. |
timeout_ms | integer or null | no | |
url | string (uri) | yes | The endpoint: https, a public name, no IP literal and no embedded credentials, checked by the egress guard at save and at every request. |
Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
201 | application/json | PreCallHookCreated | |
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 |
422 | application/json | ErrorEnvelope | validation_failed |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 201 answer
The shape is PreCallHookCreated.
| Field | Type | Required | Description |
|---|---|---|---|
allowed_agent_ids | array of AgentId | yes | Agents besides the routed one whose published versions a response may select; empty allows only versions of the routed Agent. |
consecutive_failures | integer | yes | |
created_at | Timestamp | yes | |
default | PreCallHookDefault or null | yes | |
directions | array of PreCallHookDirection | yes | |
id | PreCallHookId | yes | |
object | "pre_call_hook" | yes | |
on_failure | PreCallHookOnFailure | yes | |
phi_attested_at | Timestamp or null | yes | When an owner attested the endpoint for PHI; null before. |
phi_attested_by | MemberId or null | yes | |
previous_secret_expires_at | Timestamp or null | yes | |
previous_secret_hint | string or null | yes | |
revision | integer | yes | |
scope | PreCallHookScope | yes | |
secret | PreCallHookSecret or null | yes | The secret, shown in this answer only; null on a replay under the same Idempotency-Key, which creates nothing. |
secret_hint | string | yes | The last four characters of the current secret. |
status | PreCallHookStatus | yes | |
timeout_ms | integer or null | yes | The deadline of a request; null for the default of each direction. |
updated_at | Timestamp | yes | |
url | string | yes | The endpoint. |