Skip to content

App events (webhook)

Without the webhook, your app only notices that the person disconnected when a call fails. With it, Canverly tells you right away. The webhook complements the error signals, it does not replace them: keep handling 401 invalid_token and invalid_grant (see Connect Canverly).

Give the events URL in the app screen or in the registration request. Same rules as redirect URIs: https, public host, no wildcard, no fragment, no credentials.

Canverly generates one whsec_... secret per app. It is shown once, on creation or rotation, and stored encrypted. Treat it like the client_secret: server-side only, never in logs.

In the app registration API the secret comes in the eventos_webhook_segredo field of the creation POST response. Rotation (POST .../webhook-secret/rotate) answers {"segredo":"whsec_..."} with Cache-Control: no-store. Registration errors: WEBHOOK_URI_INVALIDA (422, URL breaks the rules above), WEBHOOK_SEM_URI (422, rotation with no URL registered) and WEBHOOK_UNAVAILABLE (503, retry).

type When
grant.revoked The person, the company owner, the operator or the daily routine revoked the link (or the app was disabled). The grant’s tokens stop working.
grant.updated The sites or scopes of the grant changed. Re-read the canverly block (via /oauth/introspect or the next /oauth/token).
grant.expiring The grant’s refresh token expires within 7 days. See grant.expiring.

Notices about posts (post.published, post.updated and others) have their own body and rules; see Post events.

{
"type": "grant.revoked",
"id": "evt_01J9ZKD0E1F2G3H4J5K6M7N8P9",
"timestamp": "2026-10-22T14:03:21Z",
"data": {
"grant_id": "0199c2f1-0b44-7d20-8a6e-3c5d7f9a1b22",
"client_id": "0199c2f0-7a31-7c11-9d52-1f3a6b8e4c10",
"iss": "https://auth.canverly.net",
"sub": "pw_8f3a1c9d2e7b4a60",
"org": "01J9ZK3M4N5P6Q7R8S9T0V1W2X",
"sites": ["01J9ZKC1D2E3F4G5H6J7K8M9N0"],
"motivo": "usuario"
}
}
  • sub is the person’s pairwise identifier for your app, the same as in the id_token. The account key in your app is (iss, sub): iss tells which ring it came from (.com or .net), and the same human has a different sub in each.
  • sites is a list of ids or the string "todos" (the whole company was granted).
  • motivo (in grant.revoked): usuario, dono_da_empresa, operador, app_desativado, refresh_reuso, perdeu_acesso or conta_encerrada.
  • No name, e-mail or token. Ignore unknown fields: Canverly only adds fields.

Official schemas: oauth-app-webhook.grant.revoked.v1, oauth-app-webhook.grant.updated.v1 and oauth-app-webhook.grant.expiring.v1 in the contracts repository. The grant.expiring one diverges from the code (section grant.expiring).

grant.expiring warns that a grant’s live refresh token will expire within 7 days. It only reaches an app that has an events URL and secret registered; an app without them does not receive the notice and the grant is not even marked.

{
"type": "grant.expiring",
"id": "evt_01JAX7Q5R8S9T0V1W2X3Y4Z5A7",
"timestamp": "2026-10-24T09:00:00Z",
"data": {
"grant_id": "0199c2f1-0b44-7d20-8a6e-3c5d7f9a1b22",
"client_id": "chimpee",
"iss": "https://auth.canverly.net",
"sub": "pw_8f3a1c9d2e7b4a60",
"org": "01J9ZK3M4N5P6Q7R8S9T0V1W2X",
"sites": ["01J9ZKC1D2E3F4G5H6J7K8M9N0"],
"expires_at": "2026-10-31T09:00:00Z",
"reason": "idle",
"days_left": 7
}
}

The values above illustrate the format the auth code builds; they are not from a real event.

data field Meaning
grant_id The grant UUID.
client_id The app’s public identifier (the slug, such as chimpee).
iss, sub, org Issuer, the person’s pairwise identifier for your app, and company. Same rule as grant.revoked.
sites A list of site ids (ULID) or the text "todos" (the whole company, future sites included).
expires_at When the refresh stops renewing (RFC 3339, UTC).
reason idle: 30 days of idleness is about to run out. ceiling: the absolute 90-day cap, only on an app without sem_teto_absoluto.
days_left Whole days until expires_at, rounded up, from 1 to 7 (7 on the normal emission).

The event never carries a token (cvt_, cvr_), a secret or an e-mail. Headers, signature, expected response and retries are those of grant.revoked (sections below): webhook-id is the id (evt_ plus a ULID), up to 8 attempts in 24 hours, and outside production it only goes to hosts on the integration list (OAUTH_WEBHOOKS_ALLOWLIST, up to 5 hosts); the rest go to the log sink.

  • An auth routine runs when the server starts and every 6 hours. It selects active grants, not yet notified, of an active app with an events URL and secret, whose live refresh expires within 7 days.
  • The notice goes out once per cycle. The marker is cleared on refresh rotation only if the new validity is more than 7 days ahead. A rotation that keeps the validity inside the window (such as a partner near the 90-day cap) does not reopen the cycle.
  • With OAUTH_WEBHOOKS_ENABLED off nothing is marked or queued, so the notice goes out once the flag is turned on. Delivery needs the auth worker running.
  • On idle, using the refresh before expires_at renews the window. On ceiling, rotation does not postpone the expiry.

File events/schemas/oauth-app-webhook.grant.expiring.v1.json in the contracts repository:

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://contracts.canverly.com/events/oauth-app-webhook.grant.expiring.v1.json",
"title": "oauth-app-webhook.grant.expiring.v1",
"description": "Webhook ENTREGUE ao app OAuth (Standard Webhooks, mesmo entregador e allowlist anti-SSRF de grant.revoked/grant.updated; piso 18: fora de prd só vai a host da allowlist) avisando que o grant vence em até 7 dias. Corpo = este JSON; assinatura nos cabeçalhos webhook-id/-timestamp/-signature. Produtor: rotina do canverly-auth que roda a cada 6 horas (passada do servidor; não é diária). Uma vez por ciclo (auth.oauth_grants.aviso_expiracao_em; zera quando o grant é usado de novo). reason `idle`: ociosidade de 30 dias vai estourar; `ceiling`: teto absoluto de 90 dias (só parceiro; app grupo não tem teto). `client_id` é o SLUG do app no catálogo (não ULID/UUID). `sites` é a lista de ids de site liberados ao grant ou a string `todos` (grant da empresa inteira, inclusive sites futuros). `sub` é o identificador PAIRWISE do app (o app é o destinatário e já o conhece); NUNCA carrega token (`cvt_`/`cvr_`), segredo nem e-mail. Plano 2026-10-24-chimpee-autonomia item 8.",
"type": "object",
"required": [
"type",
"id",
"timestamp",
"data"
],
"additionalProperties": false,
"properties": {
"type": {
"const": "grant.expiring"
},
"id": {
"type": "string",
"pattern": "^evt_[0-9A-HJKMNP-TV-Z]{26}$",
"description": "Id do evento (ULID); o app deduplica por ele"
},
"timestamp": {
"type": "string",
"format": "date-time",
"description": "Hora da emissão do aviso (UTC, RFC 3339)"
},
"data": {
"type": "object",
"required": [
"grant_id",
"client_id",
"iss",
"sub",
"org",
"sites",
"expires_at",
"reason",
"days_left"
],
"additionalProperties": false,
"properties": {
"grant_id": {
"type": "string",
"format": "uuid",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
"description": "Id do grant em UUID (o ULID interno reescrito em UUID)"
},
"client_id": {
"type": "string",
"pattern": "^[a-z0-9][a-z0-9-]{1,61}[a-z0-9]$",
"description": "SLUG do app no catálogo (ex.: chimpee), o mesmo `client_id` do OAuth"
},
"iss": {
"type": "string",
"format": "uri",
"pattern": "^https://",
"description": "Emissor (issuer) OIDC do auth"
},
"sub": {
"type": "string",
"minLength": 1,
"maxLength": 128,
"description": "Identificador pairwise da pessoa para ESTE app"
},
"org": {
"type": "string",
"pattern": "^[0-9A-HJKMNP-TV-Z]{26}$",
"description": "Id da empresa (ULID)"
},
"sites": {
"oneOf": [
{
"const": "todos"
},
{
"type": "array",
"items": {
"type": "string",
"pattern": "^[0-9A-HJKMNP-TV-Z]{26}$"
},
"uniqueItems": true
}
],
"description": "Ids (ULID) dos sites liberados ao grant, ou `todos` quando o grant cobre a empresa inteira (inclusive sites futuros). Lista vazia nunca é emitida (vira `todos`)."
},
"expires_at": {
"type": "string",
"format": "date-time",
"description": "Quando o grant deixa de renovar (ociosidade ou teto)"
},
"reason": {
"enum": [
"idle",
"ceiling"
]
},
"days_left": {
"type": "integer",
"minimum": 1,
"maximum": 7,
"description": "Dias inteiros até expires_at (a janela do aviso é (agora+6d, agora+7d], logo 7 na emissão normal)"
}
}
}
}
}

The published schema (contract aligned in canverly-contracts, PR #41) declares data.sites, client_id as the app slug, grant_id as a UUID and org as a ULID, and the routine that emits the notice runs every 6 hours.

The notice renews nothing: it only says when and why. What the auth code does with the refresh token supports the following (the action is a recommendation to the integrator, the refresh behavior is the server’s):

  • reason: "idle": any refresh made before expires_at rotates the token and renews the 30-day window. If the app uses the link, one refresh now is enough (serialized per grant_id, see Connect Canverly). If the link is idle on purpose, let it expire and handle invalid_grant later.
  • reason: "ceiling": the 90-day ceiling is inherited by the following refresh tokens, so rotating does not postpone expires_at. The only way is to redo “Connect”: a new authorization creates a new refresh family and the ceiling starts over. The consent screen always appears, so warn the person ahead of time and send them through the Connect Canverly flow.
  • After expires_at with no renewal: the refresh answers invalid_grant and the API answers 401 invalid_token once the access token expires. Mark the link as disconnected and ask for a new connection.

Besides the grant.* notices, the app can subscribe to notices about changes to posts on the sites its grant covers. It is opt-in per app: with no subscription no post event is sent. The body carries neither the post content nor personal data; the app reads the post through the API, with the scope it already has (for example GET /v1/posts/{reference}/source).

Post events are only queued with OAUTH_WEBHOOKS_POSTS_ENABLED and OAUTH_WEBHOOKS_ENABLED both on in the auth; if either is off nothing is sent.

There are six, and only these. The type in the body is the value you store in the subscription.

type When Minimum scope on the grant
post.published A post was published. posts:read
post.updated A post was edited. posts:read
post.unpublished A post was taken offline. posts:read
post.pending.promoted The pending edit of a published post was promoted live (see Revisions and pending edit). posts:read
post.pending.discarded The pending edit was discarded. posts:drafts:read, posts:update or posts:write
post.scheduled A post was scheduled to publish at a future time. posts:drafts:read, posts:update or posts:write

A grant with draft scopes only does not receive the published facts (published, updated, unpublished, pending.promoted).

Other authoring events (creation, autosave, deletion, restore, editorial or SEO change, pending_saved and the scheduled-promotion failure, among others) do not become webhooks. In particular, the failure of a scheduled promotion (authoring.post.pending_promotion_failed.v1) does not reach the app by webhook: read schedule_status and schedule_failure on the pending edit.

  • The app field is eventos_post_tipos: a list of up to 6 of the types above, without repetition. The empty list, which is the default, means no post events. A value outside the list gives 422 pointing at the eventos_post_tipos field.
  • The field is written by the operator’s internal apps API, on creation (POST) and on edit (PATCH, which requires the operator_admin role); [] unsubscribes. The diff goes into the audit trail. Since the integrator has no access to that API, ask the Canverly team for the subscription.
  • The app must have the events URL and the secret registered, as described in Register the URL and keep the secret. Without both, nothing is delivered even with subscribed types.

Canverly sends one event per app. The app receives it when all of this holds:

  1. the app is active, has an events URL and secret, and is subscribed to the type;
  2. there is an active grant of the app in the same company as the post that covers the post’s site (a grant with no site list covers every site of the company);
  3. the grant’s scopes are enough for the type (table above);
  4. if OAUTH_RESTRICAO_POST_TYPES_ENABLED is on, the grant’s post_types includes the post’s content type (an empty list means all);
  5. the event is not an edit made by the app itself (next section).

If several grants of the same app cover the event, the oldest one wins and its grant_id goes in the body.

So the app does not react to what it wrote itself, post.updated is suppressed when the author of the edit is an app (actor.type = oauth_app in the authoring event) and that app’s client_id is the recipient app’s. The decision uses the app that made the write, not the grant_id. Consequences:

  • Only post.updated is suppressed. post.published, post.unpublished, post.scheduled and the post.pending.* arrive even when caused by the app itself.
  • An edit made by another app arrives, with actor.kind = "app" and the other app’s client_id.
  • An edit made by a person or by an API key arrives with actor.kind = "user"; the name of the person or key never leaves.
{
"type": "post.updated",
"id": "evt_01JB4Q8R2S3T4V5W6X7Y8Z9A0B",
"timestamp": "2026-10-25T13:05:41Z",
"data": {
"grant_id": "0199c2f1-0b44-7d20-8a6e-3c5d7f9a1b22",
"client_id": "chimpee",
"iss": "https://auth.canverly.net",
"org": "01J9ZK3M4N5P6Q7R8S9T0V1W2X",
"site_id": "01J9ZKC1D2E3F4G5H6J7K8M9N0",
"occurred_at": "2026-10-25T13:05:40Z",
"source_event_id": "01JB4Q8R1F2G3H4J5K6M7N8P9Q",
"post": {
"id": "01JB4Q7A1B2C3D4E5F6G7H8J9K",
"slug": "how-to-choose-a-server",
"post_type": "post",
"url": "https://www.example.com/how-to-choose-a-server",
"version": "tok9",
"status": "published"
},
"actor": { "kind": "user" }
}
}

The values illustrate the format the auth code builds; they are not from a real event.

Field Meaning
type, id, timestamp Same envelope as grant.*. The id (evt_ plus a ULID) is derived from the source event and the app, so redelivery of the same fact has the same id. timestamp is the enqueue time.
data.grant_id UUID of your app’s grant that covers the event (the oldest, if several). It is not the grant of whoever edited.
data.client_id Slug of the recipient app (your client_id).
data.iss Issuer (same as in the id_token).
data.org, data.site_id ULIDs of the company and the post’s site.
data.occurred_at Time of the fact in authoring (RFC 3339, UTC).
data.source_event_id event_id of the authoring event that originated the delivery.
data.post.id, slug, post_type Identifier, slug and content type of the post.
data.post.url Public URL of the post. It is the post’s canonical_url when there is one; otherwise https://<site primary domain>[/<language prefix>]/<slug>. Omitted if the site has no resolved domain and no canonical.
data.post.version The post’s ETag after the write, the same value as the PATCH If-Match. Omitted if authoring did not supply it. Use it to tell whether the text you hold went stale.
data.post.status Post status after the fact.
data.actor.kind user (person or API key), app or system.
data.actor.client_id Only when kind is app: the slug of the app that acted.

There is no sub, e-mail, name or token. Ignore fields you do not know: Canverly only adds fields. The schemas are oauth-app-webhook.post.published.v1, oauth-app-webhook.post.updated.v1, oauth-app-webhook.post.unpublished.v1, oauth-app-webhook.post.pending.promoted.v1, oauth-app-webhook.post.pending.discarded.v1 and oauth-app-webhook.post.scheduled.v1, in the contracts repository (PR #39).

The signature, the headers, the 5-second deadline, the up-to-8 attempts in 24 hours and the idempotency by webhook-id are exactly those of grant.revoked (sections below). What changes is the origin: the auth reads the fact from authoring through a durable queue, and if it cannot process it, it tries again and, on the tenth failure, moves it to an error queue for the team. There is no guaranteed ordering between events of the same post: use data.post.version and a read through the API to decide which state holds. Outside production, only the hosts on the integration list receive; the others go to the log sink.

Delivery follows Standard Webhooks.

Header Content
webhook-id Same as the body id (evt_...). Use it for idempotency.
webhook-timestamp Seconds since 1970 (UTC) at send time. Changes on each attempt.
webhook-signature v1,<base64> of HMAC-SHA256(key, "<webhook-id>.<webhook-timestamp>.<body>"). May carry several space-separated signatures (secret rotation); one match is enough.

The HMAC key is the base64-decoded text after whsec_ (Standard Webhooks), not the secret text itself.

  1. Read the raw body (the exact bytes received) before any JSON parsing.
  2. Recommended: reject if webhook-timestamp is more than 5 minutes from your clock (replay protection). This is a recommendation to integrators, not a Canverly rule.
  3. Compute the HMAC and compare in constant time.
  4. Only then parse and process.

Node 22:

import { createHmac, timingSafeEqual } from 'node:crypto';
const SEGREDO = process.env.CANVERLY_WEBHOOK_SECRET; // whsec_...
const chave = Buffer.from(SEGREDO.replace(/^whsec_/, ''), 'base64');
/** Devolve true se a assinatura bate e o relógio está dentro de 5 min. */
export function verificar(corpoCru, cabecalhos) {
const id = cabecalhos['webhook-id'];
const ts = cabecalhos['webhook-timestamp'];
const assinaturas = cabecalhos['webhook-signature'];
if (!id || !ts || !assinaturas) return false;
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
const esperado = createHmac('sha256', chave)
.update(`${id}.${ts}.${corpoCru}`)
.digest();
return assinaturas.split(' ').some((par) => {
const [versao, b64] = par.split(',');
if (versao !== 'v1' || !b64) return false;
const recebido = Buffer.from(b64, 'base64');
return recebido.length === esperado.length && timingSafeEqual(recebido, esperado);
});
}

Go:

package canverly
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"fmt"
"math"
"net/http"
"strconv"
"strings"
"time"
)
// Verificar confere assinatura e janela de 5 min. corpo = bytes crus da requisição.
func Verificar(segredo string, h http.Header, corpo []byte) bool {
id, ts, sigs := h.Get("webhook-id"), h.Get("webhook-timestamp"), h.Get("webhook-signature")
if id == "" || ts == "" || sigs == "" {
return false
}
seg, err := strconv.ParseInt(ts, 10, 64)
if err != nil || math.Abs(float64(time.Now().Unix()-seg)) > 300 {
return false
}
chave, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(segredo, "whsec_"))
if err != nil {
return false
}
mac := hmac.New(sha256.New, chave)
fmt.Fprintf(mac, "%s.%s.", id, ts)
mac.Write(corpo)
esperado := mac.Sum(nil)
for _, par := range strings.Split(sigs, " ") {
v, b64, ok := strings.Cut(par, ",")
if !ok || v != "v1" {
continue
}
recebido, err := base64.StdEncoding.DecodeString(b64)
if err == nil && hmac.Equal(recebido, esperado) {
return true
}
}
return false
}

Use it to check your implementation before going live. 32-byte key of 0x0b; the secret is whsec_ followed by the base64 of those bytes.

Item Value
Secret whsec_CwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCwsLCws=
webhook-id evt_01J
webhook-timestamp 1700000000
Body {"type":"grant.revoked"}
webhook-signature v1,XBl1eMbMuv+caVAk7VCcpJTwpjDx7hhOB7mUXvP4b1Q=

(The vector tests the signature only; with so old a timestamp, switch the clock-window check off in the test.)

  • Reply 2xx fast (Canverly waits up to 5 seconds and does not follow redirects). Do heavy work later in your own queue.
  • Any other response, timeout or connection failure is a failure. Canverly retries with growing delays, up to 8 attempts within 24 hours. After that the event is marked falhou on Canverly’s side (with an alert) and is not resent automatically.
  • So the same event may arrive more than once, out of order. Store processed webhook-ids and ignore repeats (recommendation: keep them at least 48 hours, longer than the 24 h of retries). Make the effect idempotent.
  • Do not trust ordering: a grant.updated after a grant.revoked for the same grant_id leaves the grant revoked.
  • Delivery only goes to addresses resolving to public IPs: localhost, private networks and link-local are refused at connect time. To test locally use a tunnel with a public host.
  • The webhook is a notice only. Confirm current state with /oauth/introspect when in doubt; never trust a body whose signature you did not verify.

Ask the team for a rotation. The new secret is shown once. Update your server and only then discard the old one.