CastBricks Docs

Webhooks

Receive real-time event notifications from CastBrick to your server

Webhooks

Webhooks let CastBrick push real-time event notifications to your server. When an event occurs (e.g. an SMS is delivered or a contact opts out), CastBrick sends an HTTP POST request to your registered endpoint with a JSON payload.


Event types

EventTrigger
SmsSentAn SMS has been dispatched to the carrier
SmsDeliveredCarrier confirmed delivery
SmsFailedDelivery failed
InboundMessageAn inbound SMS was received
DeliveryReceiptA delivery receipt was received from the carrier
ContactCreatedA contact was added
ContactUpdatedA contact was updated
ContactDeletedA contact was deleted
CampaignCreatedA broadcast was created
CampaignUpdatedA broadcast was updated
CampaignDeletedA broadcast was deleted
OptOutA contact replied STOP or opted out
LowBalanceYour SMS balance fell below the alert threshold

Create a webhook

POST /webhooks

Registers a new webhook endpoint for a specific event type.

Request body

{
  "endpoint": "https://yourapp.com/webhooks/castbrick",
  "eventType": "SmsDelivered"
}
FieldTypeRequiredDescription
endpointstringYesHTTPS URL that will receive POST requests
eventTypestringYesOne of the event types listed above

Response 201

"3fa85f64-5717-4562-b3fc-2c963f66afa6"

Returns the new webhook ID.

Code sample

curl -X POST https://api.castbrick.co/webhooks \
  -H "Authorization: Bearer cb_live_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "endpoint": "https://yourapp.com/webhooks/castbrick",
    "eventType": "SmsDelivered"
  }'

List webhooks

GET /webhooks

Returns a paginated list of your registered webhooks.

Query parameters

ParameterDefaultDescription
pageNumber1Page number
pageSize10Results per page

Response 200

{
  "items": [
    {
      "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
      "endpoint": "https://yourapp.com/webhooks/castbrick",
      "eventType": "SmsDelivered",
      "isActive": true,
      "createdAt": "2026-01-15T10:00:00Z"
    }
  ],
  "totalCount": 3,
  "pageNumber": 1,
  "totalPages": 1,
  "hasNextPage": false,
  "hasPreviousPage": false
}

Code sample

curl https://api.castbrick.co/webhooks \
  -H "Authorization: Bearer cb_live_xxxxxxxxxxxx"

Get a webhook

GET /webhooks/{id}

curl https://api.castbrick.co/webhooks/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
  -H "Authorization: Bearer cb_live_xxxxxxxxxxxx"

Toggle active status

PUT /webhooks/{id}/toggle

Enables or disables a webhook. When disabled, no events are sent to its endpoint.

curl -X PUT https://api.castbrick.co/webhooks/3fa85f64-5717-4562-b3fc-2c963f66afa6/toggle \
  -H "Authorization: Bearer cb_live_xxxxxxxxxxxx"

Returns 204 No Content.


Test a webhook

POST /webhooks/test

Sends a sample payload to your webhook endpoint so you can verify it's reachable and responding correctly.

Request body

{
  "webhookId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "payload": "{\"event\":\"SmsDelivered\",\"messageId\":\"test-123\"}"
}

Code sample

curl -X POST https://api.castbrick.co/webhooks/test \
  -H "Authorization: Bearer cb_live_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "webhookId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "payload": "{\"event\":\"SmsDelivered\",\"messageId\":\"test-123\"}"
  }'

Delivery logs

GET /webhooks/{id}/logs

Returns the delivery history for a webhook, including status and response for each attempt.

Query parameters

ParameterDefaultDescription
limit50Number of log entries to return

Response 200

[
  {
    "id": "log-uuid",
    "webhookId": "3fa85f64-...",
    "eventType": "SmsDelivered",
    "statusCode": 200,
    "attempt": 1,
    "deliveredAt": "2026-05-07T10:24:00Z"
  }
]

Code sample

curl "https://api.castbrick.co/webhooks/3fa85f64-5717-4562-b3fc-2c963f66afa6/logs?limit=20" \
  -H "Authorization: Bearer cb_live_xxxxxxxxxxxx"

Retry a delivery

POST /webhooks/logs/{logId}/retry

Retries a failed webhook delivery by its log entry ID.

curl -X POST https://api.castbrick.co/webhooks/logs/log-uuid/retry \
  -H "Authorization: Bearer cb_live_xxxxxxxxxxxx"

Delete a webhook

DELETE /webhooks/{id}

Permanently removes a webhook. Returns 204 No Content.

curl -X DELETE https://api.castbrick.co/webhooks/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
  -H "Authorization: Bearer cb_live_xxxxxxxxxxxx"

Receiving events

CastBrick sends a POST request to your endpoint with a JSON body. Your server must return a 2xx status code within 10 seconds, otherwise the delivery is marked as failed and may be retried.

Example payload — SmsDelivered

{
  "event": "SmsDelivered",
  "messageId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "recipientPhone": "+244923000000",
  "deliveredAt": "2026-05-07T10:23:08Z"
}

Example handler (Node.js / Express)

app.post('/webhooks/castbrick', express.json(), (req, res) => {
  const { event, messageId } = req.body;

  if (event === 'SmsDelivered') {
    console.log('Delivered:', messageId);
  } else if (event === 'SmsFailed') {
    console.warn('Failed:', messageId);
  }

  res.sendStatus(200);
});

Example handler (Python / Flask)

from flask import Flask, request

app = Flask(__name__)

@app.route('/webhooks/castbrick', methods=['POST'])
def handle_webhook():
    data = request.get_json()
    event = data.get('event')

    if event == 'SmsDelivered':
        print('Delivered:', data.get('messageId'))
    elif event == 'SmsFailed':
        print('Failed:', data.get('messageId'))

    return '', 200