Cardify.Sdk
1.0.8
See the version list below for details.
dotnet add package Cardify.Sdk --version 1.0.8
NuGet\Install-Package Cardify.Sdk -Version 1.0.8
<PackageReference Include="Cardify.Sdk" Version="1.0.8" />
<PackageVersion Include="Cardify.Sdk" Version="1.0.8" />
<PackageReference Include="Cardify.Sdk" />
paket add Cardify.Sdk --version 1.0.8
#r "nuget: Cardify.Sdk, 1.0.8"
#:package Cardify.Sdk@1.0.8
#addin nuget:?package=Cardify.Sdk&version=1.0.8
#tool nuget:?package=Cardify.Sdk&version=1.0.8
Cardify .NET SDK
Official .NET SDK for the Cardify API - A powerful library for creating and managing cards with REST API integration.
Installation
Via NuGet Package Manager
dotnet add package Cardify.Sdk
Via Package Manager Console
Install-Package Cardify.Sdk
Quick Start
Basic Setup
using Cardify.Sdk;
using Cardify.Sdk.Configuration;
// Option 1: Initialize with Bearer Token
var client = new CardifyApiClient("https://localhost:44329", "your-access-token");
// Option 2: Initialize with API Key
var client = CardifyApiClient.WithApiKey("https://localhost:44329", "your-api-key");
// Option 3: Use CardifyApiOptions for advanced configuration
var options = new CardifyApiOptions
{
BaseUrl = "https://localhost:44329",
AccessToken = "your-access-token", // For Bearer token
// ApiKey = "your-api-key", // For API Key (alternative)
TimeoutSeconds = 60
};
var client = new CardifyApiClient(options);
Card API
Initialize Card Fields from REST API
This endpoint allows you to populate card template fields by calling an external REST API.
Authentication: Supports both Bearer Token and API Key authentication.
Authorization:
- With Bearer Token: Requires
CardifyPermissions.Card.Createpermission - With API Key: Full access (bypasses user permissions)
using Cardify.Sdk;
using System.Collections.Generic;
// Create the client
var client = new CardifyApiClient("https://localhost:44329", "your-access-token");
// Prepare the input
var input = new InitCardFieldsFromRestApiInput
{
TemplateId = 1,
// Path parameters for the REST API (e.g., /api/users/{userId})
PathParams = new List<KeyValueEntity>
{
new KeyValueEntity { Key = "userId", Value = "123", IsStatic = true }
},
// Headers for the REST API request
Headers = new List<KeyValueEntity>
{
new KeyValueEntity { Key = "Authorization", Value = "Bearer token123", IsStatic = true },
new KeyValueEntity { Key = "Content-Type", Value = "application/json", IsStatic = true }
},
// Query parameters for the REST API (e.g., ?filter=active)
Params = new List<KeyValueEntity>
{
new KeyValueEntity { Key = "filter", Value = "active", IsStatic = false },
new KeyValueEntity { Key = "limit", Value = "10", IsStatic = true }
},
// Body parameters for POST/PUT requests
Body = new List<KeyValueEntity>
{
new KeyValueEntity { Key = "name", Value = "John Doe", IsStatic = false },
new KeyValueEntity { Key = "email", Value = "john@example.com", IsStatic = false }
}
};
// Call the API
try
{
var result = await client.Cards.InitCardFieldsFromRestApiAsync(input);
// Access the card design
Console.WriteLine($"Card Width: {result.Width}");
Console.WriteLine($"Card Height: {result.Height}");
Console.WriteLine($"Temp Metadata ID: {result.TempMetadataId}");
Console.WriteLine($"Data JSON: {result.DataJson}");
// Access front face fields
if (result.Front != null)
{
Console.WriteLine($"Front has {result.Front.Fields.Count} fields");
foreach (var field in result.Front.Fields)
{
Console.WriteLine($" Field ID: {field.Id}, Value: {field.Value}");
}
}
// Access back face fields
if (result.Back != null)
{
Console.WriteLine($"Back has {result.Back.Fields.Count} fields");
}
}
catch (CardifyApiException ex)
{
Console.WriteLine($"API Error: {ex.Message}");
Console.WriteLine($"Status Code: {ex.StatusCode}");
Console.WriteLine($"Response: {ex.ResponseContent}");
}
Models
InitCardFieldsFromRestApiInput
Input model for initializing card fields from a REST API.
| Property | Type | Description |
|---|---|---|
TemplateId |
int |
The ID of the card template to use |
PathParams |
List<KeyValueEntity>? |
Path parameters for the REST API URL |
Headers |
List<KeyValueEntity>? |
HTTP headers for the REST API request |
Params |
List<KeyValueEntity>? |
Query parameters for the REST API request |
Body |
List<KeyValueEntity>? |
Body parameters for POST/PUT requests |
CardDesignWithMetadata
Response model containing the card design and metadata.
| Property | Type | Description |
|---|---|---|
TempMetadataId |
Guid? |
Temporary metadata identifier |
DataJson |
string? |
JSON string containing the card data |
Front |
CardFace? |
Front face design of the card |
Back |
CardFace? |
Back face design of the card |
Width |
int? |
Width of the card in pixels |
Height |
int? |
Height of the card in pixels |
KeyValueEntity
Represents a key-value pair for API parameters.
| Property | Type | Description |
|---|---|---|
Key |
string? |
The parameter key/name |
Value |
string? |
The parameter value |
IsStatic |
bool? |
Whether the value is static or dynamic |
Error Handling
The SDK throws CardifyApiException when an API request fails:
try
{
var result = await client.Cards.InitCardFieldsFromRestApiAsync(input);
}
catch (CardifyApiException ex)
{
// Access error details
Console.WriteLine($"Error Message: {ex.Message}");
Console.WriteLine($"HTTP Status Code: {ex.StatusCode}");
Console.WriteLine($"Response Content: {ex.ResponseContent}");
}
Configuration
CardifyApiOptions
| Property | Type | Default | Description |
|---|---|---|---|
BaseUrl |
string |
Required | Base URL of the Cardify API |
AccessToken |
string? |
null |
Bearer token for authentication |
ApiKey |
string? |
null |
API Key for authentication (sent as ApiKey header) |
TimeoutSeconds |
int |
30 |
HTTP request timeout in seconds |
Note: If both AccessToken and ApiKey are provided, AccessToken takes precedence.
Important: The API Key must be configured in the Cardify API's appsettings.json under the ApiKeys section for authentication to work.
Authentication Methods
Using Bearer Token
// Method 1: Constructor
var client = new CardifyApiClient(
"https://localhost:44329",
"your-bearer-token"
);
// Method 2: Options
var options = new CardifyApiOptions
{
BaseUrl = "https://localhost:44329",
AccessToken = "your-bearer-token"
};
var client = new CardifyApiClient(options);
Using API Key
// Method 1: Static factory method (recommended)
var client = CardifyApiClient.WithApiKey(
"https://localhost:44329",
"your-api-key"
);
// Method 2: Options
var options = new CardifyApiOptions
{
BaseUrl = "https://localhost:44329",
ApiKey = "your-api-key"
};
var client = new CardifyApiClient(options);
API Key Configuration (Server Side):
Add your API keys to appsettings.json on the Cardify API server:
{
"ApiKeys": [
"your-api-key-1",
"your-api-key-2"
]
}
Advanced Usage
Dependency Injection
using Microsoft.Extensions.DependencyInjection;
using Cardify.Sdk;
using Cardify.Sdk.Configuration;
// In Startup.cs or Program.cs
services.AddSingleton(sp =>
{
var options = new CardifyApiOptions
{
BaseUrl = configuration["Cardify:BaseUrl"],
AccessToken = configuration["Cardify:AccessToken"]
};
return new CardifyApiClient(options);
});
// Inject in your service/controller
public class MyService
{
private readonly CardifyApiClient _cardifyClient;
public MyService(CardifyApiClient cardifyClient)
{
_cardifyClient = cardifyClient;
}
public async Task CreateCard()
{
var result = await _cardifyClient.Cards.InitCardFieldsFromRestApiAsync(...);
}
}
Using CancellationToken
using var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(10));
try
{
var result = await client.Cards.InitCardFieldsFromRestApiAsync(input, cts.Token);
}
catch (OperationCanceledException)
{
Console.WriteLine("Request was cancelled");
}
Requirements
- .NET 8.0 or higher
- System.Net.Http.Json
- Microsoft.Extensions.Http
License
This SDK is part of the Cardify project.
Support
For issues, questions, or contributions, please visit:
Changelog
Version 1.0.0
- Initial release
- Support for
InitCardFieldsFromRestApiAsyncendpoint - Basic authentication with Bearer token
- Comprehensive error handling
- Full XML documentation
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- System.Net.Http.Json (>= 8.0.0)
- System.Text.Json (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.