Getting Started
This guide walks you through installing the Kard Go SDK, authenticating with the Kard API, and making your first request.
Prerequisites
- Go 1.18+
KARD_CLIENT_IDandKARD_CLIENT_SECRET
Create a Client
Import and instantiate the client using your credentials.
This SDK supports two authentication methods:
OAuauth Client Credentials
Bearer Token Authentication
The client automatically handles authentication, retries, and timeouts.
Environments
This SDK allows you to configure different environments for API requests with the option.WithBaseURL option.
Make Your First API Calls
1. Creating a User:
To enhance offer targeting and attribution, you can include a hashed email (HEM) when creating users. The SDK includes a built-in hem.GenerateHEM utility that normalizes and hashes email addresses:
The function normalizes the email before hashing (removes whitespace, lowercases, and handles Gmail-specific rules like dot and + suffix removal). It returns an error for invalid inputs.
2. Fetching Offers for User with Extended API:
3. Submitting Transaction for User:
All SDK methods return typed responses and typed errors.
Handling Errors
If an API request fails (4xx or 5xx), the SDK returns a structured error compatible with errors.Is and errors.As.
Common Configuration Options
Configure Retries
Retries are enabled by default (max 2 attempts) with exponential backoff. The SDK retries on status codes 408, 429, and 5xx. Configure with option.WithMaxAttempts:
Set a Timeout
Use the standard context library to set a per-request timeout.
Access Raw HTTP Responses
To inspect headers or status codes, use WithRawResponse.
Explicit Null
To send an explicit null through an optional parameter, use the setter methods on the request object; they flip a bit in explicitFields so the property is serialized rather than omitted.
Custom HTTP Client
A variety of request options are included to adapt the behavior of the library, which includes configuring authorization tokens, or providing your own instrumented *http.Client.
Providing your own *http.Client is recommended. Otherwise, the http.DefaultClient will be used, and your client will wait indefinitely for a response (unless the per-request, context-based timeout is used).