Getting Started
This guide walks you through installing the Kard Java SDK, authenticating with the Kard API, and making your first request.
Prerequisites
- Java 8+
KARD_CLIENT_IDandKARD_CLIENT_SECRET- Build tool: Maven or Gradle
Install the SDK
Gradle
Add the dependency in your build.gradle file:
Maven
Add the dependency in your pom.xml file:
Create a Client
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.
Environments
This SDK allows you to configure different environments for API requests.
Base URL
You can set a custom base URL when constructing the client.
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 throws an IllegalArgumentException for invalid inputs.
3. Submitting Transaction for User:
All SDK methods return typed responses and throw typed errors.
Handling Errors
If an API request fails (4xx or 5xx), the SDK throws a KardApiApiException.
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.
Set a Timeout
The SDK defaults to a 60 second timeout. Timeouts can be configured at the client or request level.
Add Custom Headers
Headers can be configured at the client or request level.
Access Raw HTTP Responses
To inspect headers or status codes, use withRawResponse():
Custom HTTP Client
The SDK works with any OkHttpClient instance. By default, the SDK constructs one, but you can provide your own.