Skip to main content

Configure Webhooks

After choosing an event from the event catalog, use the REST API to register and manage its webhook. The access token used for these requests needs the Webhook (oa_webhooks) scope, regardless of event type. Additional scopes are needed only if you also use the corresponding API functions. See Authentication: Scopes for scope configuration.

1. Prepare Your Endpoint​

An endpoint is the HTTPS URL in your application that receives CleverReach requests. It must be publicly reachable when you register it. If you are developing locally, start a tunnel first and use the public HTTPS URL it provides.

Before registering, prepare the endpoint to handle two request types:

  • Verification (GET): Read the secret query parameter and respond with your verification token, followed by a space and the secret value. The verification token is the verify value you will send in the registration request.
  • Events (POST): Accept a JSON request body. After registration, check the x-cr-calltoken header against the call_token returned by the API. Return a successful HTTP status, such as 200, within 5 seconds to acknowledge receipt. The event does not have to be fully processed before you respond. If processing takes longer, persist or enqueue it before acknowledging it, then process it asynchronously.

An event may be delivered more than once, for example after a failed response or timeout. The documented payloads do not include a delivery ID or event timestamp. Before going live, confirm with the backend team whether a stable delivery ID is available in a request header. If so, use it to deduplicate retries.

If there is no stable delivery ID, treat webhook events as change notifications: use the resource ID in payload to fetch the current record and perform an idempotent upsert keyed by that record's ID. For deletion events, make deletion or tombstone handling idempotent using the resource ID. Do not repeat side effects when the same notification is delivered again.

2. Register the Webhook​

Register for an entire event category or a specific event. For example, receiver subscribes to all receiver events, while receiver.subscribed subscribes only to subscription events.

Send a POST request to https://rest.cleverreach.com/hooks/eventhook. This request triggers the verification GET described above, so make sure your endpoint is ready first.

{
"url": "https://example.com/cleverreach-webhook",
"event": "receiver",
"condition": "1939",
"verify": "your-verification-token"
}
FieldDescription
urlHTTPS endpoint that receives webhook requests and verification requests.
eventEvent name or category to register for.
conditionOptional filter, such as a group ID for receiver events.
verifyVerification token between 10 and 50 characters.

3. Save the Registration Response​

A successful registration returns a call_token and a secret:

{
"success": true,
"call_token": "your-call-token",
"secret": "your-encryption-secret"
}

Store both values securely. Check the x-cr-calltoken header on event requests against the returned call_token. The secret is used to decrypt sensitive payload fields.

Manage Registrations​

MethodEndpointDescription
POSThttps://rest.cleverreach.com/hooks/eventhookRegister a webhook for an event.
GEThttps://rest.cleverreach.com/hooks/eventhookList registered webhooks.
DELETEhttps://rest.cleverreach.com/hooks/eventhook/{eventname}Delete a webhook for an event.
DELETEhttps://rest.cleverreach.com/hooks/eventhook/{eventname}/{condition}Delete a webhook with a condition.

Use GET /hooks/eventhook to list registrations. To remove a registration, send a DELETE request to /hooks/eventhook/{eventname}. Include /{condition} to delete only the registration for a specific condition. A successful deletion returns 200. A missing registration returns 404.

Encrypted Payloads​

Some payloads contain encrypted values, such as receiver email addresses in deletion events. Decrypt them with the secret returned when you registered the webhook.

PropertyValue
AlgorithmAES-256-CBC
Key derivationSHA-256 hash of the secret
Initialization vectorFirst 16 bytes of the encrypted data
<?php
function decode($encrypted, $secret) {
$enc_bin = hex2bin($encrypted);
$key = hash('sha256', $secret, true);
$iv = substr($enc_bin, 0, 16);
return openssl_decrypt(substr($enc_bin, 16), 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
}

Store the secret securely. Use it only for decryption and never expose it in logs or responses.