C# Examples for adaline.ink
C# code examples for the Adaline platform API using HttpClient.
Examples use .NET's built-in HttpClient. No NuGet packages required.
Setup
using System.Net.Http;
using System.Text;
using System.Text.Json;
class AdalineClient
{
private const string BaseUrl = "https://api.adaline.ink";
private static readonly HttpClient client = new();
private static string accessToken = "";
static async Task<string> ApiRequest(HttpMethod method, string path, string? body = null)
{
var request = new HttpRequestMessage(method, BaseUrl + path);
request.Headers.Add("Authorization", $"Bearer {accessToken}");
if (body != null)
request.Content = new StringContent(body, Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
return await response.Content.ReadAsStringAsync();
}
}
Authentication
static async Task Login(string email, string password)
{
var body = JsonSerializer.Serialize(new { email, password });
var content = new StringContent(body, Encoding.UTF8, "application/json");
var response = await client.PostAsync($"{BaseUrl}/api/v1/auth/login", content);
var json = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
accessToken = json.RootElement.GetProperty("access_token").GetString()!;
}
static async Task Main(string[] args)
{
await Login("you@example.com", "your-password");
}
Upload a Document
static async Task<JsonElement> UploadDocument(string orgId, string filePath)
{
using var form = new MultipartFormDataContent();
using var fileStream = File.OpenRead(filePath);
form.Add(new StreamContent(fileStream), "file", Path.GetFileName(filePath));
var request = new HttpRequestMessage(HttpMethod.Post,
$"{BaseUrl}/api/v1/documents/upload?org_id={orgId}");
request.Headers.Add("Authorization", $"Bearer {accessToken}");
request.Content = form;
var response = await client.SendAsync(request);
var json = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
return json.RootElement;
}
var doc = await UploadDocument("your-org-id", "syllabus.pdf");
Console.WriteLine($"Uploaded: {doc.GetProperty("id")} ({doc.GetProperty("doc_type")})");
List Documents
var docs = await ApiRequest(HttpMethod.Get, "/api/v1/documents/?org_id=your-org-id");
Console.WriteLine(docs);
Compliance Check
var report = await ApiRequest(HttpMethod.Post, "/api/v1/compliance/test",
JsonSerializer.Serialize(new { document_id = docId }));
var json = JsonDocument.Parse(report).RootElement;
Console.WriteLine($"Score: {json.GetProperty("overall_score")}% " +
$"(Grade {json.GetProperty("grade")})");
Start Conversion
var job = await ApiRequest(HttpMethod.Post, "/api/v1/conversions/",
JsonSerializer.Serialize(new { document_id = docId }));
Console.WriteLine(job);
// Poll status
var status = await ApiRequest(HttpMethod.Get, $"/api/v1/conversions/{jobId}");
Console.WriteLine(status);
Tags
var tag = await ApiRequest(HttpMethod.Post, "/api/v1/tags",
JsonSerializer.Serialize(new { name = "reviewed", color = "green", org_id = orgId }));
await ApiRequest(HttpMethod.Post, $"/api/v1/tags/{tagId}/documents/{docId}");
Public Share
var share = await ApiRequest(HttpMethod.Post,
$"/api/v1/documents/{docId}/public-share", "{}");
Console.WriteLine(share);
Batch Upload and Score
static async Task BatchUploadAndScore(string orgId, string directory)
{
var extensions = new[] { ".pdf", ".docx", ".pptx" };
foreach (var file in Directory.GetFiles(directory)
.Where(f => extensions.Contains(Path.GetExtension(f).ToLower())))
{
Console.WriteLine($"Processing {Path.GetFileName(file)}...");
try
{
var doc = await UploadDocument(orgId, file);
var docId = doc.GetProperty("id").GetString();
var report = await ApiRequest(HttpMethod.Post, "/api/v1/compliance/test",
JsonSerializer.Serialize(new { document_id = docId }));
var json = JsonDocument.Parse(report).RootElement;
Console.WriteLine($" Score: {json.GetProperty("overall_score")}% " +
$"({json.GetProperty("grade")})");
}
catch (Exception ex)
{
Console.WriteLine($" Error: {ex.Message}");
}
}
}