CastBricks Docs

Go SDK

Install and use the official CastBrick Go SDK

Go SDK

castbrick-go is the official Go SDK. No external dependencies — uses only the standard library.

Installation

go get github.com/IldySilva/castbrick-go

Initialization

import "github.com/IldySilva/castbrick-go/castbrick"

cb := castbrick.New(os.Getenv("CASTBRICK_API_KEY"))

Custom HTTP client

cb := castbrick.NewWithOptions(
    os.Getenv("CASTBRICK_API_KEY"),
    "https://api.castbrick.com/v1",
    &http.Client{Timeout: 10 * time.Second},
)

SMS

Send

result, err := cb.SMS.Send(ctx, castbrick.SendSmsOptions{
    To:       []string{"+244923000000", "+244912000000"},
    Content:  "Your verification code is 1234",
    SenderID: "MyApp", // optional
})

Schedule for later

t := time.Now().Add(2 * time.Hour)
result, err := cb.SMS.Send(ctx, castbrick.SendSmsOptions{
    To:          []string{"+244923000000"},
    Content:     "Scheduled message",
    ScheduledAt: &t,
})

List / Get / Cancel

page, err := cb.SMS.List(ctx, 1, 20)
fmt.Println(page.TotalCount)

msg, err := cb.SMS.Get(ctx, "message-id")
fmt.Println(msg.Status)

err = cb.SMS.CancelScheduled(ctx, "message-id")

Contacts

// List (with optional search)
page, err := cb.Contacts.List(ctx, 1, 20, "joão")

// Get
contact, err := cb.Contacts.Get(ctx, "contact-id")

// Create (comma-separated phone numbers)
created, err := cb.Contacts.Create(ctx, "", "+244923000000,+244912000000")

// Delete
err = cb.Contacts.Delete(ctx, "contact-id")

// Contact lists
list, err := cb.Contacts.CreateList(ctx, "VIP Customers")
err = cb.Contacts.AddToList(ctx, list.ID, contact.ID)
err = cb.Contacts.RemoveFromList(ctx, list.ID, contact.ID)

Broadcasts

// Create
id, err := cb.Broadcasts.Create(ctx, castbrick.CreateBroadcastOptions{
    Name:          "Black Friday",
    Message:       "50% off everything today!",
    ContactListID: listID,  // optional
    SenderID:      "MyApp", // optional
})

// Send immediately
err = cb.Broadcasts.Send(ctx, id)

// Update with schedule
t := time.Date(2026, 11, 28, 9, 0, 0, 0, time.UTC)
_, err = cb.Broadcasts.Update(ctx, id, castbrick.UpdateBroadcastOptions{
    Name:       "Black Friday",
    Message:    "50% off everything today!",
    ScheduleAt: &t,
})

// Other operations
err = cb.Broadcasts.Cancel(ctx, id)
newID, err := cb.Broadcasts.Duplicate(ctx, id)
err = cb.Broadcasts.Delete(ctx, id)

Error Handling

import "errors"

_, err := cb.SMS.Send(ctx, ...)
var apiErr *castbrick.APIError
if errors.As(err, &apiErr) {
    fmt.Printf("%d: %s\n", apiErr.StatusCode, apiErr.Body)
    // 401 → invalid or revoked API key
    // 402 → insufficient credits
    // 422 → validation error
}