Skip to main content

C# (.NET 8) SDK Guide (AptiaOne.Sdk)

The C# client SDK provides modern, strongly-typed asynchronous clients targeting .NET 8.0+ with nullable reference types.


Installation​

Via NuGet Package Manager​

dotnet add package AptiaOne.Sdk

From Downloaded Bundle​

Download the zip archive from the Download Center, extract it, and add a project reference:

<ItemGroup>
<ProjectReference Include="..\AptiaOne.Sdk\AptiaOne.Sdk.csproj" />
</ItemGroup>

Architecture Note: Token Exchange​

No Built-In OAuth Token Exchange

AptiaOne.Sdk does not exchange client credentials or manage token refresh lifecycles automatically. The calling application retrieves the Bearer token from AWS Cognito and sets it on the Configuration object.


Complete Executable Example​

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using AptiaOne.Sdk.Api;
using AptiaOne.Sdk.Client;
using AptiaOne.Sdk.Model;

namespace AptiaOneIntegrationSample
{
public class Program
{
public static async Task Main(string[] args)
{
bool isSandbox = true;
string baseUrl = isSandbox
? "https://api.development.aptiaone.com"
: "https://api.development.aptiaone.com";
string authUrl = isSandbox
? "https://auth-api-development-us-east-1.auth.us-east-1.amazoncognito.com"
: "https://auth-api-development-us-east-1.auth.us-east-1.amazoncognito.com";

string clientId = Environment.GetEnvironmentVariable("APTIA_CLIENT_ID") ?? "your-client-id";
string clientSecret = Environment.GetEnvironmentVariable("APTIA_CLIENT_SECRET") ?? "your-client-secret";
string tenantId = "tenant-001";

try
{
// Step 1: Acquire Bearer Token from Cognito
string accessToken = await GetCognitoTokenAsync(authUrl, clientId, clientSecret);

// Step 2: Configure SDK Client
var config = new Configuration
{
BasePath = baseUrl,
AccessToken = accessToken
};
config.DefaultHeaders["X-Aptia-Tenant-Id"] = tenantId;
config.DefaultHeaders["X-Correlation-Id"] = Guid.NewGuid().ToString();

// Step 3: Instantiate Typed API Service
var participantsApi = new ParticipantsApi(config);

// Step 4: Invoke Endpoint
ParticipantListResponse response = await participantsApi.ListParticipantsAsync(
pageNumber: 1,
pageSize: 10,
search: "Doe"
);

Console.WriteLine($"Found {response.TotalCount} participants:");
if (response.Items != null)
{
foreach (var p in response.Items)
{
Console.WriteLine($"- {p.FirstName} {p.LastName} (ID: {p.Id}, Status: {p.EmploymentStatus})");
}
}
}
catch (ApiException ex)
{
Console.WriteLine($"Aptia API Error ({ex.ErrorCode}): {ex.Message}");
}
}

private static async Task<string> GetCognitoTokenAsync(string authUrl, string clientId, string clientSecret)
{
using var httpClient = new HttpClient();
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "client_credentials"),
new KeyValuePair<string, string>("client_id", clientId),
new KeyValuePair<string, string>("client_secret", clientSecret),
new KeyValuePair<string, string>("scope", "aptia/participants.read aptia/enrollments.read")
});

var response = await httpClient.PostAsync($"{authUrl}/oauth2/token", content);
response.EnsureSuccessStatusCode();

string json = await response.Content.ReadAsStringAsync();
using var doc = JsonDocument.Parse(json);
return doc.RootElement.GetProperty("access_token").GetString()!;
}
}
}