Getting Started
C# Getting Started
This guide walks you through installing the Kard .NET SDK, authenticating with the Kard API, and making your first request.
Prerequisites
- .NET Framework 4.6.2+ or .NET Standard 2.0+
KARD_CLIENT_IDandKARD_CLIENT_SECRET
Install the SDK
Create a Client
Import and instantiate the KardClient using your credentials.
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.
Environments
You can configure a custom base URL by setting BaseUrl on ClientOptions.
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 ArgumentException 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.
Handling Errors
If an API request fails (4xx or 5xx), the SDK throws a KardApiException.
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 the MaxRetries request option:
Set a Timeout
The SDK defaults to a 30 second timeout. Override it with the Timeout request option.
Add Custom Headers
Use the AdditionalHeaders request option to send extra headers.
Add Query Parameters
Use the AdditionalQueryParameters request option to send extra query params.
Access Raw HTTP Responses
To inspect status codes, headers, or the URL, use .WithRawResponse().
Forward Compatible Enums
This SDK uses forward-compatible enums that handle unknown values gracefully.