SDKs
Go SDK
Install github.com/dimmihq/dimmi-go to call the REST API, iterate paginated lists, sign identity tokens, and verify webhooks.
The official Go SDK requires Go 1.22 or later.
go get github.com/dimmihq/dimmi-goCreate a client and call the API
Section titled “Create a client and call the API”package main
import ( "context" "errors" "fmt" "log" "net/url" "os"
dimmi "github.com/dimmihq/dimmi-go" "github.com/dimmihq/dimmi-go/api")
func main() { ctx := context.Background()
client, err := dimmi.New(dimmi.WithToken(os.Getenv("DIMMI_TOKEN"))) if err != nil { log.Fatal(err) }
res, err := client.API.ConversationsIndexWithResponse(ctx, nil) if err != nil { var apiErr *dimmi.Error if errors.As(err, &apiErr) { log.Fatal(apiErr.Status, " ", apiErr.Code, " ", apiErr.Fields) } log.Fatal(err) } for _, conversation := range *res.JSON200.Data { fmt.Println(conversation.Id, conversation.Status) }
open := dimmi.List[api.Conversation](client, "/conversations", url.Values{"filter[status]": {"open"}}) for open.Next(ctx) { fmt.Println(open.Item().Id) } if err := open.Err(); err != nil { log.Fatal(err) }}Set DIMMI_TOKEN to your API token. dimmi.New() reads DIMMI_TOKEN automatically even if you omit WithToken.
Ways to call endpoints
Section titled “Ways to call endpoints”- Typed methods:
client.APIgenerates one method per operation ID (for example,conversations.indexbecomesConversationsIndexWithResponse). - Raw requests: call
client.Do(ctx, method, path, query, body, &out)for any/api/v1path and decode JSON intoout. - Pagination: use
dimmi.List[T]for cursor-based lists (meta.next_cursor) anddimmi.Pages[T]for page-numbered lists. Both exposeNext,Item,Err, andAll.
Handle errors
Section titled “Handle errors”API errors return *dimmi.Error with Status, Code, Message, Fields, and RetryAfter. Match status groups with errors.Is:
| Sentinel error | HTTP status |
|---|---|
dimmi.ErrBadRequest |
400 |
dimmi.ErrUnauthorized |
401 |
dimmi.ErrForbidden |
403 |
dimmi.ErrNotFound |
404 |
dimmi.ErrConflict |
409 |
dimmi.ErrValidation |
422 |
dimmi.ErrRateLimited |
429 |
dimmi.ErrServer |
500+ |
Client options
Section titled “Client options”| Option | Default | What it does |
|---|---|---|
WithToken |
DIMMI_TOKEN, then DIMMI_API_TOKEN |
Sets the API token. |
WithBaseURL |
DIMMI_BASE_URL, then https://trydimmi.com |
Points the client at a self-hosted server. |
WithMaxRetries |
3 |
Retries on 429, 503, or dropped connections. |
WithMaxRetryWait |
60 seconds | Max Retry-After wait before returning the error. |
WithTimeout |
30 seconds | Total timeout per call, including retries. |
The Go client attaches an Idempotency-Key to every POST and reuses it across retries. Pass dimmi.IdempotencyKey(key) as the last argument on a generated method to supply your own key.
Webhooks and identity tokens
Section titled “Webhooks and identity tokens”Use dimmi.NewWebhook(secret) to verify webhooks (see Verify webhook signatures) and dimmi.SignIdentityToken to mint JWTs for identity verification.