Webhooks

Envless.webhooks.rotate_secret

Issue a new signing secret for an endpoint

def rotate_secret(id, timeout: nil)

Generates a new signing secret for the endpoint and returns it. This is the only route that can hand you a usable secret after create, and the returned secret is again returned exactly once: reads only ever give secretLastFour, so losing it means rotating again.

There is no dual secret grace window. The old secret stops verifying the instant the call commits, so deliveries already in flight were signed with the old one and will fail at your receiver, and any retry of an earlier failure is re-signed with the new one. Expect a short window of rejected requests.

The safe sequence is to deploy a receiver that accepts both the current secret and a new one read from config, call this, write the returned secret to config, then drop the old value once lastSuccessAt starts advancing again. If you cannot do that, rotate during a quiet period and plan for the failures.

Example

ruby
require "envless/sdk"

endpoint_id = "0194f2b1-9c3a-7c21-8f0e-2b6d4a1c5e90"
rotated = Envless.webhooks.rotate_secret(endpoint_id)

puts rotated[:secret]
puts "#{rotated[:secretLastFour]} #{rotated[:secretRolledAt]}"

Parameters

ParameterTypeRequiredDescription
idStringYesEndpoint id, ids only and no slug form.
timeout:Integer | Float | RationalNoSeconds each attempt of this call may take, redirects and the response body included, before it raises Envless::NetworkError with timeout? set. Overrides the client's timeout for this call, and 0 turns the limit off.

Returns

rotated_secret_resource with the new secret, its secretLastFour and the secretRolledAt timestamp.

Worth knowing

  • There is no request body and the success status is 200, not 201, because nothing new is created.
  • Pass the full secret including the ev_whsec_ prefix to verify_webhook_signature.
  • Emits webhook.secret_rotated, which carries secretLastFour and secretRolledAt but never the secret.

Required scopes

webhooks:write

Underlying endpoint

POST /webhooks/{id}/rotate

Request and response schema, every error code, and a live playground.

In TypeScript

envless.webhooks.rotateSecret()

The same method in @goenvless/sdk, with the same request, retries and errors.