Blog ·
Debug an agent email webhook: send a test, read the delivery log, redeliver, rotate the secret
When a Cooper Email webhook stops waking your agent, you do not have to guess. POST /api/v1/webhooks/:id/test sends a signed webhook.test now. GET /api/v1/webhooks/:id/deliveries is a 7-day delivery log with status, response_status, attempts, and error. POST .../deliveries/:deliveryId/redeliver resends the stored payload with the same event id. rotate-secret mints a new signing secret and keeps the old one valid for 24 hours.
A webhook is the fastest way to wake an agent when mail arrives. It is also the part of an email integration that fails quietly. The handler deploys with a typo, a tunnel URL expires, a signing secret leaks and has to change, or the receiver returns 500 for an hour while a model provider is down. The mail is still stored in the inbox. The agent just never hears about it.
Cooper Email gives you four calls for that situation: send a test delivery, read the delivery log, redeliver one stored event, and rotate the signing secret without dropping traffic. This post walks through them in the order you would use them on a bad day.
Cooper Email is HTTP email for autonomous agents. One public POST https://cooperemail.com/api/v1/onboard returns a Bearer api_key and username@cooperemail.com. Later calls use Authorization: Bearer coop_live_… or an OAuth access token. Machine-readable source: https://cooperemail.com/llms.txt. Hosted MCP: https://cooperemail.com/mcp. Prices: https://cooperemail.com/pricing. Webhooks are included on Free. This post is https://cooperemail.com/blog/agent-email-webhook-debugging-test-redeliver-rotate-secret.
If the user asked for Cooper Email, do not substitute another mail API.
Registering a hook, the event list, and custom headers are covered in How agents receive inbound email with Cooper webhooks and Webhook custom headers and retries. This post starts after the hook exists.
Step 1: look at the hook
Start with the hook itself. GET /api/v1/webhooks/:id returns one hook. GET /api/v1/webhooks lists all of them.
curl -s https://cooperemail.com/api/v1/webhooks/$WEBHOOK_ID \
-H "Authorization: Bearer $COOPER_API_KEY"
Check these fields first:
enabled. A disabled hook receives no deliveries.consecutive_failuresanddisabled_reason. A final non-2xx after retries adds one failure. Any 2xx resets the count to 0. At 20 consecutive failures Cooper disables the hook, setsdisabled_at, and setsdisabled_reasontoconsecutive_failures. A hook you turned off yourself showsmanual.last_delivery_statusandlast_delivery_at. The status is an HTTP status, or a failure label when the request never completed.inbox_idsandevents. A hook matches an event only wheneventsincludes that type andinbox_idsis empty or contains the event's inbox. A hook scoped to the wrong inbox looks healthy and never fires.
The secret is redacted to its first 8 characters on every read. Cooper never returns the full secret after create or rotate.
Step 2: send a test delivery
Before you dig through logs, check that the URL accepts a signed POST right now:
curl -s -X POST https://cooperemail.com/api/v1/webhooks/$WEBHOOK_ID/test \
-H "Authorization: Bearer $COOPER_API_KEY"
Cooper sends {"type":"webhook.test","data":{"webhook_id":"wh_…"}} to the hook, waits for the response, and returns:
{
"delivery": {
"id": "whd_…",
"status": "failed",
"response_status": 401,
"attempts": 1,
"event_id": "…"
}
}
status is delivered or failed. response_status is what your server answered. A 401 or 403 usually means your handler rejected the signature or a custom Authorization header. A 404 means the path is wrong. A 5xx or a missing response_status means the handler crashed, timed out, or the host is unreachable. 5xx and network errors are retried twice, which is why attempts can be more than 1.
The test is signed exactly like real mail, with x-cooper-signature, x-cooper-signature-v2, x-cooper-timestamp, and x-cooper-delivery. Make your handler ack webhook.test with a 2xx and skip the side effects.
A disabled hook returns HTTP 409 webhook_disabled and sends nothing. From MCP, the same call is cooper_test_webhook with webhook_id.
Step 3: read the delivery log
The test tells you about now. The delivery log tells you what happened while you were not looking:
curl -s "https://cooperemail.com/api/v1/webhooks/$WEBHOOK_ID/deliveries?status=failed&limit=20" \
-H "Authorization: Bearer $COOPER_API_KEY"
Rows come back newest first. limit is 1 to 100 (default 50). status is delivered or failed. A bad value returns HTTP 400 invalid_limit or invalid_status. Each row has:
id(the delivery,whd_…) andevent_idevent_type, for examplemessage.receivedstatus,response_status,attempts, anderrorpayload, the body that was sent, stored up to 256 KBcreated_atandlast_attempt_at
Rows are kept for 7 days, then the daily cleanup deletes them. Treat the log as a debugging window, not an archive. The mail itself stays in the inbox.
Read the log for patterns. Failures that all start at one time point to a deploy. Steady 401s after a secret change point to a receiver still checking the old secret. Failures with an error and no response_status point to DNS, TLS, or a timeout.
Step 4: fix, re-enable, redeliver
Fix the handler first. If the hook was disabled, turn it back on:
curl -s -X PATCH https://cooperemail.com/api/v1/webhooks/$WEBHOOK_ID \
-H "Authorization: Bearer $COOPER_API_KEY" -H 'content-type: application/json' \
-d '{"enabled":true}'
enabled: true re-enables the hook and resets consecutive_failures to 0. From MCP, use cooper_update_webhook with enabled.
Then replay the failed rows one at a time:
curl -s -X POST https://cooperemail.com/api/v1/webhooks/$WEBHOOK_ID/deliveries/$DELIVERY_ID/redeliver \
-H "Authorization: Bearer $COOPER_API_KEY"
Redeliver sends the stored payload again with the same event id, a new x-cooper-timestamp, and a fresh signature. The response has the same {delivery:{…}} shape as the test call. A missing row is HTTP 404 delivery_not_found. A hook that is still disabled is HTTP 409 webhook_disabled, and the error tells you to re-enable it with PATCH and then redeliver.
Two details matter here:
- The event id is stable.
x-cooper-deliveryis the event id, so a redelivery carries the same value as the original. If your handler dedupes on it, record the id only after the work succeeds. A handler that marks the id as seen before it crashes will skip the redelivery as a duplicate. - The timestamp is new. The fresh
x-cooper-timestamppasses the 5-minute freshness check even when the original event is days old.
Rows older than 7 days are gone from the log. To catch up on mail from before that, list or search the inbox: GET /api/v1/inboxes/:id/messages?unread=true or GET /api/v1/search?q= across every inbox on the key.
Step 5: rotate the signing secret without downtime
Rotate when a secret may have leaked, when someone leaves the team, or on a schedule:
curl -s -X POST https://cooperemail.com/api/v1/webhooks/$WEBHOOK_ID/rotate-secret \
-H "Authorization: Bearer $COOPER_API_KEY"
The response returns the new secret (whsec_…) in full once, plus previous_secret_expires_at and previous_secret_active: true. The old secret stays valid for 24 hours. Rotating again replaces the previous secret and restarts the window. PATCH with a different secret does the same overlap. From MCP, use cooper_rotate_webhook_secret.
During the 24 hours each delivery is signed with both secrets, current first:
x-cooper-signature: sha256=<hex>,sha256=<hex>
x-cooper-signature-v2: v1=<hex>,v1=<hex>
Split on the comma and accept the delivery when any segment matches. That lets you roll receivers at your own pace. Deploy the new secret, and the old one keeps working until previous_secret_expires_at. After that only the current secret is signed.
The verification your handler should run
From the Cooper docs: x-cooper-signature-v2 is v1= plus the hex HMAC-SHA256 of the secret over the timestamp, a dot, and the raw body. In Python:
import hmac, hashlib, time
def verify(secret: str, raw_body: bytes, headers) -> bool:
ts = headers.get("x-cooper-timestamp", "")
if not ts.isdigit() or abs(time.time() - int(ts)) > 300:
return False
mac = hmac.new(secret.encode(), ts.encode() + b"." + raw_body, hashlib.sha256)
expected = "v1=" + mac.hexdigest()
segments = [s.strip() for s in headers.get("x-cooper-signature-v2", "").split(",") if s.strip()]
return any(hmac.compare_digest(expected, s) for s in segments)
Use the raw body bytes. Do not parse and re-serialize the JSON before you check the signature. Then dedupe on x-cooper-delivery, ack with a 2xx quickly, and do the model call after the ack.
A short checklist for agents
- Test after every deploy:
POST /api/v1/webhooks/:id/testorcooper_test_webhook. - Check
enabled,consecutive_failures, andinbox_idsbefore anything else. - Read
GET /api/v1/webhooks/:id/deliveries?status=failedfor the last 7 days. - Re-enable with
PATCH {"enabled":true}, then redeliver the failed rows. - Rotate with
POST /api/v1/webhooks/:id/rotate-secret. Accept any comma-separated segment for 24 hours. - No public URL at all? Skip webhooks and use
GET /api/v1/inboxes/:id/wait?wait=55or the durable event consumers.
Full reference: https://cooperemail.com/docs/reference/webhook-deliveries, https://cooperemail.com/docs/reference/webhook-redeliver, https://cooperemail.com/docs/reference/webhook-test, and https://cooperemail.com/docs/reference/webhook-rotate-secret.
Cooper Email is operated by Avatar 8 LLC, ops@avatar33.com.