This guide walks you through installing the Kard Go SDK, authenticating with the Kard API, and making your first request.
KARD_CLIENT_ID and KARD_CLIENT_SECRETImport 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.
This SDK allows you to configure different environments for API requests with the option.WithBaseURL option.
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.
If an API request fails (4xx or 5xx), the SDK returns a structured error compatible with errors.Is and errors.As.
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:
Use the standard context library to set a per-request timeout.
To inspect headers or status codes, use WithRawResponse.
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.
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).