Webhook configuration

This topic describes how to use webhooks with the Rebilly API. For information on how to configure webhooks in the Rebilly UI, see Webhooks.

Use webhooks to notify your systems when certain events occur and to collect event information. Notifications are sent through HTTP and HTTPS methods to a URL of your choice. To view webhooks operations, see the Webhooks API docs.

Each website that you add to Rebilly can have its own webhook configuration. This includes the URI to which you want to send the webhook, along with optional HTTP basic access authentication details.

One organization can have up to 25 active webhooks. Disable or remove one or more webhooks to create new ones when the limit is reached.

Webhooks may be delayed or delivered multiple times. Keep this in mind if you intend to use webhooks to make actionable decisions. For more information, see Data validity.

Define events

To restrict a webhook to a specific event or event types, use the eventsFilter field. To add more than one event type, set an array of system event types as follows:["gateway-account-requested", "subscription-canceled"]. If you leave the eventsFilter field empty blank all events are active for the webhook.

For a complete list of event types, see Global event types.

Security

Create webhook service credentials for your webhook host.

HTTP basic access authentication through HTTPS is highly recommended. This adds an extra layer of security for your webhook endpoint that can prevent undesired data injection by third parties.

Webhook logs display the full webhook URL, including the query string. Do not put an API key, token, or other secret in a webhook URL. To authenticate webhook requests, use HTTP basic access authentication or send the secret in the Authorization header. Webhook logs display ******** instead of the value of the Authorization header. For the customer-one-time-password-requested, account-password-reset-requested, and account-verification-requested events, webhook logs display [redacted] instead of the URL, the request and response bodies, and every header value.

Rebilly webhooks may be sent from these IP addresses. If you use HTTP basic access authentication, an authorization header is also sent along with the GET, POST, PUT, PATCH, or DELETE request.

The following is an example of a header with HTTP basic access authentication enabled that uses username = rebilly, password = superman:

POST /odt4xsod HTTP/1.1
User-Agent: Rebilly/20e49c5
Host: example.com
Content-Type: application/json; charset=utf-8
Content-Length: 478
Connection: close
Authorization: Basic cmViaWxseTpzdXBlcm1hbgo=
Accept-Encoding: gzip, deflate

If you use base64 to decode the value decode(cmViaWxseTpzdXBlcm1hbgo=) you receive rebilly:superman.

Responses

A HTTP 200 OK response is expected after a successful webhook transmission to your systems. If no response is received within 20 seconds, or the HTTP response code is not 200, the request is considered not sent and be marked for retry. The webhook is sent again automatically after approximately 5 minutes. If no response is received, the webhook is sent again with an exponential back-off at approximately 1, 2, 4, 8, and 16 hours. In total, the webhook is retried up to 6 times. If still unsuccessful, it is not attempted again.

User agent

In Rebilly, all outgoing webhooks contain a User-Agent header. The header value changes frequently. The value format is Rebilly/%release%, where %release% is a 7 character long alphanumeric string which matches the /^[a-z0-9]{7}$/ regular expression pattern.

Data validity

When a notification is triggered, all available information is sent to your endpoint at the time of the event. The data contained in the webhook reflects the state of Rebilly records at the time of the event. If there is a delay, your records might be more up to date than the data that is sent by the webhook.

The following example describes a scenario where a delay occurs in recording of data between systems.

  1. A transaction triggers a webhook, and some relating customer information was not supplied at the time when the transaction occurred.
  2. The notification transmission is delayed for a short period.
  3. Your system modifies or adds this information before a notification is received.
  4. The notification for the transaction is received by your systems, but the customer information does not match your records.

Data authenticity

In Rebilly, all outgoing webhooks contain a Security-Signature header. Use this header to ensure data authenticity. Signature verification is optional and is not required for your integration to work, but it is recommended.

The authenticity check uses JSON Web Tokens (JWTs) and JSON Web Keys (JWKs) to verify webhooks.

To authenticate webhook data:

  1. Locate, load, and cache Rebilly JWKs from the live or sandbox environments.
    To ensure proper key rotation, a cache Time to Live (TTL) of no greater than 1 hour is recommended.
  2. Extract the JWT from the Security-Signature header of the webhook.
  3. Validate the JWT against your preferred JWT and JWK library for your chosen programming language.
  4. Decode the payload (second) segment of the JWT and verify the following checks:

If a webhook fails any of the following checks, consider the webhook invalid and discard it.

  • The iss value is equal to the Rebilly API URL where you expect to receive webhooks. For example, https://api.rebilly.com/ or https://api-sandbox.rebilly.com/.
  • The aud value is equal to your organization ID within Rebilly.
  • The iat value is less than or equal to the current Unix timestamp. A leeway of no greater than 10 seconds is recommended.
  • The exp value is greater than the current Unix timestamp. This is an optional check to prevent replay attacks. Webhooks that are received within a 5-minute timeframe between the iat and exp values are accepted.
  • The requestBodyHash is equal to the SHA256 hash of the raw webhook body. Hash the request body bytes exactly as received. Do not parse and re-serialize the JSON first, because that changes escaping and produces a different hash.
Authenticity check example

The following example is of a webhook that is received at 2023-02-12 19:45:00 UTC. Formatting and spaces are preserved in the webhook body.

POST /odt4xsod HTTP/1.1
User-Agent: Rebilly/20e49c5
Host: example.com
Content-Type: application/json; charset=utf-8
Content-Length: 478
Connection: close
Security-Signature: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImI2MDNmMWY4Y2U0Y2RlMzc2NjExNzlkNGRmODNlYjZlODc0ZTRjZjRjNWNmNWRhMGIxYTY0NDUyMDJmNmJlNGIifQ.eyJpc3MiOiJodHRwczovL2FwaS1zYW5kYm94LnJlYmlsbHkuY29tLyIsImF1ZCI6ImE5ZjY4ZTZlLWUyZTYtNDNkZC1hMjdmLTgxMjAxMjFkNzQyOCIsImlhdCI6MTY3NjIzMDk3MiwiZXhwIjoxNjc2MjMxMjcyLCJyZXF1ZXN0Qm9keUhhc2giOiIyMjA1YThkMjU0M2M5N2E5YThkYzI5YTRmOWZkZjcxN2ZkOTQ3OGI5ODkxYWRmNTJhYmQ5YzA5ZjdhZmRlMDk0In0.ChVc_NAWxfZVEl4g7QhFFO8c5ZtUuTWlP60qQ7gEKtUQdWY70WyzYOREbGPodTbraSNggh1M98gaYSqcQM6vAk3op_9HQpeMtQEIGUOjNDMe2_BmwyeGtcc3_c3Ft0gsARUYatZcVCeeYi7i8Xwekj2xQKkxbkLYEkHHj3f_o2dHXdXaFVvgU2fNN9pmfq1iI2ROM_UXrpGDfsm1nfvZsFLk9cdCum3bBMpTeqelm02ojk6yHES9otoMTYqwGJ5ovyOKaPzMAUJT1tNv1xzf5YxxyBMj6CRqTMPkItrgU3nX6pPMdS5cbEWzhTUcm29WeWrXf90PqLUJTvSxIuMhUA
Accept-Encoding: gzip, deflate

{"dataExportId":"d9dd134f-0bee-46b1-bec0-992da3173336","fileId":"d348968b-41ed-4d7d-b534-02e5265c8912","eventType":"data-export-completed","_embedded":{"dataExport":{"id":"d9dd134f-0bee-46b1-bec0-992da3173336","name":"Preview","resource":"customers","format":"csv","arguments":null,"dateRange":null,"emailNotification":[],"fields":[],"recurring":null,"status":"pending","userId":"3d08e3f3-fa38-4731-9761-8a04400e05d3","recordCount":null,"scheduledTime":"2023-02-12T19:42:52+00:00","expiredTime":"2023-03-12T19:42:52+00:00","purgedTime":"2024-06-12T19:42:52+00:00","createdTime":"2023-02-12T19:42:52+00:00","updatedTime":"2023-02-12T19:42:52+00:00","_links":[{"rel":"self","href":"https:\/\/api-sandbox.rebilly.com\/organizations\/a9f68e6e-e2e6-43dd-a27f-8120121d7428\/experimental\/data-exports\/d9dd134f-0bee-46b1-bec0-992da3173336"},{"rel":"user","href":"https:\/\/api-sandbox.rebilly.com\/users\/3d08e3f3-fa38-4731-9761-8a04400e05d3"}]}},"_links":[{"rel":"dataExport","href":"https:\/\/api-sandbox.rebilly.com\/organizations\/a9f68e6e-e2e6-43dd-a27f-8120121d7428\/experimental\/data-exports\/d9dd134f-0bee-46b1-bec0-992da3173336"},{"rel":"download","href":"https:\/\/api-sandbox.rebilly.com\/organizations\/a9f68e6e-e2e6-43dd-a27f-8120121d7428\/files\/d348968b-41ed-4d7d-b534-02e5265c8912\/download"}]}

At 2023-02-12 19:45:00 UTC the JWKs located at https://api-sandbox.rebilly.com/.well-known/keys contain the following key:

[
  {
    "kty": "RSA",
    "n": "sT66o-HJLpVt5qifPS6MsFpu8dj-NZJWWJnoJMohCBHhGNL8v6EJm_kCNY43Czi0Bt5dbrFovPgcjdR1yq938hQ9Hi2SjNoddqcsvOUtThztsXitTKSutBKjVcInN_At_DxCpO8pardiR3aLR-bCClz8iSutmRaTenee6cMUkkZZRs0XRqI_gDPfAoN_f5HWZBXnu-VSUrBpT-PnzA4ICvR9ZaeU3EK3T64QhLnxuGa_o561__CR5oD79sEXILqJoD47uE22FydAvHvrgWqk0RMkBFtSdgmFkhylpAVgnGWAJqB2FLy-yLh5QMS02SxKtz89KRVRe0V4BVx5x3bTbw",
    "e": "AQAB",
    "alg": "RS256",
    "kid": "b603f1f8ce4cde37661179d4df83eb6e874e4cf4c5cf5da0b1a6445202f6be4b",
    "use": "sig"
  }
]

The JWT signature could be verified with the key whose kid value is b603f1f8ce4cde37661179d4df83eb6e874e4cf4c5cf5da0b1a6445202f6be4b as expected.

The decoded JWT payload segment provides:

{
  "iss": "https://api-sandbox.rebilly.com/",
  "aud": "a9f68e6e-e2e6-43dd-a27f-8120121d7428",
  "iat": 1676230972,
  "exp": 1676231272,
  "requestBodyHash": "2205a8d2543c97a9a8dc29a4f9fdf717fd9478b9891adf52abd9c09f7afde094"
}

Results of the verification checks:

  • The iss value is equal to the sandbox API URL.
  • The aud value is equal to the organization ID a9f68e6e-e2e6-43dd-a27f-8120121d7428.
  • The iat value is equal to 2023-02-12 19:42:52 UTC, which is less than the reception time of 2023-02-12 19:45:00 UTC.
  • The exp value is equal to 2023-02-12 19:47:52 UTC, which is greater than the reception time of 2023-02-12 19:45:00 UTC.
  • The requestBodyHash value is equal to the SHA256 hash of the raw webhook body:
sha256('{"dataExportId":"d9dd134f-0bee-46b1-bec0-992da3173336","fileId":"d348968b-41ed-4d7d-b534-02e5265c8912","eventType":"data-export-completed","_embedded":{"dataExport":{"id":"d9dd134f-0bee-46b1-bec0-992da3173336","name":"Preview","resource":"customers","format":"csv","arguments":null,"dateRange":null,"emailNotification":[],"fields":[],"recurring":null,"status":"pending","userId":"3d08e3f3-fa38-4731-9761-8a04400e05d3","recordCount":null,"scheduledTime":"2023-02-12T19:42:52+00:00","expiredTime":"2023-03-12T19:42:52+00:00","purgedTime":"2024-06-12T19:42:52+00:00","createdTime":"2023-02-12T19:42:52+00:00","updatedTime":"2023-02-12T19:42:52+00:00","_links":[{"rel":"self","href":"https:\/\/api-sandbox.rebilly.com\/organizations\/a9f68e6e-e2e6-43dd-a27f-8120121d7428\/experimental\/data-exports\/d9dd134f-0bee-46b1-bec0-992da3173336"},{"rel":"user","href":"https:\/\/api-sandbox.rebilly.com\/users\/3d08e3f3-fa38-4731-9761-8a04400e05d3"}]}},"_links":[{"rel":"dataExport","href":"https:\/\/api-sandbox.rebilly.com\/organizations\/a9f68e6e-e2e6-43dd-a27f-8120121d7428\/experimental\/data-exports\/d9dd134f-0bee-46b1-bec0-992da3173336"},{"rel":"download","href":"https:\/\/api-sandbox.rebilly.com\/organizations\/a9f68e6e-e2e6-43dd-a27f-8120121d7428\/files\/d348968b-41ed-4d7d-b534-02e5265c8912\/download"}]}');

Standard Webhooks signature

Each webhook is also signed in the Standard Webhooks format. The Security-Signature header described in Data authenticity does not change. Both checks confirm that Rebilly sent the webhook. To confirm that the webhook is for your organization, check the aud claim of the Security-Signature JWT, or verify the v2a signature with the endpoint ID of your organization. For new integrations, use the v2a signature, because it is verified against a fixed public key and does not require fetching or caching signing keys.

Each webhook carries these headers:

HeaderValue
webhook-idYour organization ID, a colon, and the unique ID of the webhook. The organization ID never contains a colon. The value is up to 100 characters long. The same ID is sent on every retry of the same webhook. Use it as an idempotency key.
webhook-timestampThe Unix timestamp, in seconds, of the delivery attempt.
webhook-signatureTwo or more signatures, separated by spaces. Each value is a version prefix, a comma, and a base64 signature. The header contains one v1a signature and one v2a signature, or two of each during a key rotation, in any order. To verify a webhook, use the v2a signature. The v1a signature remains for existing integrations.

The v2a scheme is an asymmetric Ed25519 signature of the SHA-256 hash of the signed content. The signed content is the endpoint ID, a period, the webhook-id value, a period, the webhook-timestamp value, a period, and the raw webhook body. The signature is computed over the raw 32 bytes of the hash, not over a hex or base64 form of the hash.

The endpoint ID is a text value that identifies your organization in the signed content. Each organization has one endpoint ID. The endpoint ID is not sent in a header. To build the endpoint ID, take your organization ID, replace each % with %25, and then replace each . with %2E. If your organization ID contains neither character, the endpoint ID is the same as the organization ID. Because the endpoint ID is part of the signed content, a v2a signature for one organization does not verify for another organization.

Public keys, in the whpk_ format the specification defines:

EnvironmentPublic key
Live, https://api.rebilly.com/whpk_lr2xkGO1EEdyZxVx4DKQ5XfmSjxOmwv9UcwNPbn9fFI=
Sandbox, https://api-sandbox.rebilly.com/whpk_qism49rHt4dOh6txzL3dfnMTmhQiITY1A86Y9BJGEZM=

To verify a webhook:

  1. Read the three headers.
  2. Reject the webhook if webhook-timestamp is more than 5 minutes from the current time.
  3. Build the endpoint ID from your organization ID.
  4. Build the signed content from the endpoint ID, webhook-id, webhook-timestamp, and the raw body, and hash the signed content with SHA-256.
  5. Verify one of the v2a signatures of the hash against the public key of the environment that sent the webhook.
  6. Reject the webhook if no signature verifies.

If you receive webhooks for more than one organization at one URL, read the organization ID as the text before the first : in webhook-id. Build the endpoint ID from that organization ID. Reject the webhook if that organization ID is not one of yours, and process the webhook only for that organization.

The Standard Webhooks reference libraries, up to version 1.3.0, verify only symmetric v1 signatures. These versions do not verify the v2a or v1a signatures of Rebilly webhooks. The following examples verify a v2a signature without a library. Each one takes the three request headers, the raw request body exactly as received, the whpk_ public key of the environment, and your organization ID. Each one returns false for a missing header, a malformed value, a webhook for another organization, or a signature that does not verify.

import { createHash, createPublicKey, verify } from 'node:crypto';

// headers: the request headers, lower-case names. rawBody: the request body as a string or Buffer.
export function verifyWebhook(headers, rawBody, publicKey, organizationId) {
  const raw = Buffer.from(publicKey.replace(/^whpk_/, ''), 'base64');
  const key = createPublicKey({
    key: { kty: 'OKP', crv: 'Ed25519', x: raw.toString('base64url') },
    format: 'jwk',
  });
  const timestamp = Number(headers['webhook-timestamp']);
  if (!headers['webhook-id'] || !Number.isFinite(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > 300) {
    return false;
  }
  const endpointId = organizationId.replaceAll('%', '%25').replaceAll('.', '%2E');
  const digest = createHash('sha256')
    .update(`${endpointId}.${headers['webhook-id']}.${headers['webhook-timestamp']}.`)
    .update(rawBody)
    .digest();
  return (headers['webhook-signature'] ?? '')
    .split(' ')
    .filter((value) => value.startsWith('v2a,'))
    .some((value) => verify(null, digest, key, Buffer.from(value.slice(4), 'base64')));
}

Verify a v1a signature

The webhook-signature header also contains a v1a signature, so an integration that verifies v1a signatures continues to work. The Standard Webhooks specification deprecates v1a in favor of v2a. No end date is set for v1a signatures.

The v1a scheme is an asymmetric Ed25519 signature of the signed content, with no hash. The signed content is the webhook-id value, a period, the webhook-timestamp value, a period, and the raw webhook body. The v1a signed content does not include the endpoint ID, so the webhook-id check is required.

To verify a v1a signature:

  1. Read the three headers.
  2. Reject the webhook if webhook-id does not start with your organization ID followed by :.
  3. Reject the webhook if webhook-timestamp is more than 5 minutes from the current time.
  4. Build the signed content from webhook-id, webhook-timestamp, and the raw body.
  5. Verify one of the v1a signatures against the public key of the environment that sent the webhook.
  6. Reject the webhook if no signature verifies.

Test webhooks

This process describes how to test webhooks in the sandbox environment using the Rebilly API.

  1. Obtain IDs and a secret API key

    This step describes how to obtain your website ID, organization ID, and secret API key from your Rebilly sandbox account.

    When you first log in to Rebilly, you create an organization as part of the setup process. A default website is created when a new organization is created. For more information, see Organizations and websites.

    1. Log in or sign up to Rebilly.
    2. Obtain your organization ID and website ID:
      1. In the left navigation bar, press Settings.
      2. In the Management section, press My organization & websites.
      3. In the Organization details section, note the ID value.
      4. In the Website section, note the ID value. For more information, see Organizations and websites.
    3. Obtain your secret API key:
      A secret key is displayed in full only once, after you create it. If you stored a secret key when you created it, use that key. Otherwise, create a new secret key:
      1. In the left navigation bar, press Automations.
      2. In the Development section, press API keys.
      3. Press Create API key and create a secret key.
        For more information, see Create an API key.
      4. Press Copy, store the key in a secure place, and press Done.
  2. Create webhook credentials

    This step describes uses an interactive component to create webhook credentials in the sandbox environment. For more information, see Create a service credential.

    How to use the interactive example
    1. Enter your organization ID:
      1. Locate and press server /, then in the Server variables section, press .
      2. In the Value field, enter your organization ID and press Save.
    2. Specify that you want to create a service credential of type webhook:
      1. Locate and press {type}, then press Edit in path.
      2. In the Value field, enter webhook.
    3. Enter your secret API key:
      1. Press Security.
      2. In the API key field, enter your secret Rebilly sandbox API key.
        For more information, see Obtain IDs and API keys.
    4. Press Send.
      In the response, take note of the hash value. You will use this value in the next step.
    Loading...
  3. Trigger a webhook

    This step describes uses an interactive component to trigger a test webhook in the sandbox environment. For more information, see Trigger a test webhook.

    How to use the interactive example
    1. Enter your organization ID:
      1. Locate and press server /, then in the Server variables section, press .
      2. In the Value field, enter your organization ID and press Save.
    2. Enter your secret API key:
      1. Press Security.
      2. In the API key field, enter your secret Rebilly sandbox API key.
        For more information, see Obtain IDs and API keys.
    3. Enter your webhook credentials hash:
      1. Press Body.
      2. In the credentialHash field, enter the hash value you obtained when you created webhook credentials, as described in Step 2.
    4. Press Send.
    Loading...

Alternatively, use the Rebilly UI to test a webhook.

If you leave the eventsFilter field empty all events are active for the webhook.

Example event notification

All events are described in the Rebilly API documentation. for an example, see the invoice paid event.

For more information on Rebilly resources, see Concepts.

Retry policy for webhooks

When a webhook is triggered and an HTTP 200 OK response is not received, the webhook is marked for retry.

In both the sandbox and live environments, the webhook is automatically resent after approximately 5 minutes. The webhook is then resent at exponentially increasing intervals of approximately 1, 2, 4, 8, and 16 hours. In total, the webhook is retried up to 6 times. If still unsuccessful, it is not attempted again.

In the sandbox environment, if the webhook is unsuccessful after 48 hours and 70 consecutive attempts, the corresponding webhook subscriber is disabled.