This guide walks you through installing the Kard Java SDK, authenticating with the Kard API, and making your first request.
KARD_CLIENT_ID and KARD_CLIENT_SECRETGradle
Add the dependency in your build.gradle file:
Maven
Add the dependency in your pom.xml file:
Import and instantiate the KardApiClient using your credentials.
This SDK supports two authentication methods:
OAuth Client Credentials
Bearer Token Authentication
The client automatically handles authentication, retries, and timeouts.
This SDK allows you to configure different environments for API requests.
You can set a custom base URL when constructing the client.
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 throws an IllegalArgumentException for invalid inputs.
2. Fetching Offers for User with Extended API:
3. Submitting Transaction for User:
All SDK methods return typed responses and throw typed errors.
If an API request fails (4xx or 5xx), the SDK throws a KardApiApiException.
Retries are enabled by default (max 2 attempts) with exponential backoff. The SDK retries on status codes 408, 429, and 5xx.
The SDK defaults to a 60 second timeout. Timeouts can be configured at the client or request level.
Headers can be configured at the client or request level.
To inspect headers or status codes, use withRawResponse():
The SDK works with any OkHttpClient instance. By default, the SDK constructs one, but you can provide your own.