This guide walks you through installing the Kard TypeScript SDK, authenticating with the Kard API, and making your first request.
KARD_CLIENT_ID and KARD_CLIENT_SECRETnpm, yarn, or pnpmSupported runtimes: Node.js 18+, Vercel, Cloudflare Workers, Deno v1.25+, Bun 1.0+, React Native
Import and instantiate the KardApiClient using your credentials.
You can also configure the SDK using environment variables.
If KARD_CLIENT_ID and KARD_CLIENT_SECRET are set in your runtime environment, the SDK will automatically use them, so you can initialize the client without passing credentials explicitly.
The client automatically handles authentication, retries, and timeouts.
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 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 a TypeError 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.
The SDK exports all request and response types for full TypeScript support.
If an API request fails (4xx or 5xx), the SDK throws a KardApiError.
Retries are enabled by default (max 2 attempts).
To inspect headers or status codes, use withRawResponse():
Logging is disabled by default. Enable it during development to debug requests.
The SDK provides a way for you to customize the underlying HTTP client / Fetch function.