CLOUSD
Open account

Run automation

Webhooks

Get a call to your server when a task ends or a phone needs attention.

Add a webhook

In the dashboard: Settings → Connections → Events → Webhooks. Or through the API:

Subscribe
POST /v1/webhooks
{"url": "https://example.com/clousd", "events": ["run.completed", "run.failed"], "description": "orders bot"}
# → 201 {"webhook": {"id": "wh_3c1a", …}, "secret": "whsec_…"}   the secret is shown once

Empty events means all of them. A key can have up to ten webhooks; each one has its own secret. POST /v1/webhooks/{id}/rotate gives a new secret, /toggle pauses deliveries, /test sends a test event now, GET …/deliveries lists recent deliveries with the response code and time.

Events

EventWhen
run.completedA task finished; the body has the run with its answer.
run.failedA task could not be finished; the body says why.
run.cancelledA task was stopped.
run.waitingA task stopped to ask a question or for permission.
device.problemA phone's health check failed.
device.resolvedThe problem cleared.

Verify the signature

Each delivery is a POST with a JSON body and the header X-Clousd-Signature: t=<unix time>,v1=<hex>, where the hex is HMAC-SHA256 of "<t>.<raw body>" keyed with your webhook secret. Reject old timestamps to stop replays.

Python
import hashlib, hmac, time

def valid(body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    t, sig = parts.get("t", ""), parts.get("v1", "")
    if not t.isdigit() or abs(time.time() - int(t)) > tolerance:
        return False
    mac = hmac.new(secret.encode(), t.encode() + b"." + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(mac, sig)

Retries

Each event is tried up to four times: at once, after 30 seconds, after 5 minutes and after 30 minutes. Answer with any 2xx to confirm. The body is {"id", "type", "created", "data"} and the same id comes in X-Clousd-Event-Id: if a retry reaches you after a slow success, skip the id you have already handled. After 20 failed deliveries in a row the webhook pauses itself; turn it back on in the dashboard or with /toggle.