Using Webhooks

Learn how you can take advantage of webhooks to get real-time updates

Our systems allow you to receive real-time updates about events as they happen. You can opt into this functionality by using webhooks hosted in your environment.

Setting Up Webhooks

Once you have a webhook endpoint available in your environment, you can register it in our systems by using our Create webhook endpoint. This will provide you with a webhook ID. With the webhook registered, you can then associate events with it via our Update webhook endpoint. An example of how to do this is given below.

When a webhook has events associated with it, our systems will notify it whenever a matching event occurs. For example, if you opt into the transaction.authorized event, your webhook will be notified each time a transaction is authorized for one of your issued cards.

If your webhook requires a form of authentication, you can provide an access token for your created webhook by including the authorization_token parameter containing the token as part of your request.

Example: Setting Up A New Webhook With Authentication

import os
import requests

API_URL = "https://api.dba.thepennyinc.com/v1"
ACCESS_TOKEN = os.getenv("PENNY_ACCESS_TOKEN")

headers = {
  "Authorization": f"Bearer {ACCESS_TOKEN}"
}

payload = {
  "url": "https://<your-webhook-endpoint>",
  "events": ["transaction.authorized"],
  "authorization_token": "<your-webhook-authorization-token>"
}
response = requests.post(API_URL + "/webhooks", json=payload, headers=headers)

Event Formats

Once your webhook is set up successfully, it will be notified of new events as they occur. These payloads are JSON formatted with the following general structure:

{
  "event_id": "",
  "event_identifier": "",
  "data": {...},
}

This structure can be broken down as follows:

  • event_id is the unique identifier for the event and can be used for lookup purposes
  • event_identifier describes the type of event that has occurred. For example transaction.authorized
  • data contains detailed information about the event. Its structure changes depending on the type of event