Rowland LogoRowland

.NET

Rowland SDK for .NET

Installation

dotnet add package Rowland.DocumentsApi.Sdk

Requirements

  • .NET 9.0+
  • API key from Rowland

Quick Start

using DocumentsApi.Sdk.Clients;

var apiBaseUrl = "https://documents.rowland.ai";
var apiKey = "your-api-key-here";

var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(apiBaseUrl);
var client = new DocumentsApiClient(httpClient, apiKey);

try
{
    // Test health endpoint
    var health = await client.GetHealthAsync();
    Console.WriteLine($"Health check: {health["status"]}");

    // Upload a document
    using var fileStream = File.OpenRead("document.pdf");
    var document = await client.UploadDocumentAsync(fileStream, "document.pdf");
    Console.WriteLine($"Uploaded: {document.Id}");
}
finally
{
    httpClient.Dispose();
}

### `docs/documents-api/sdks/dotnet/quickstart.mdx`
```mdx
---
title: .NET SDK Quick Start
description: Get started with the Rowland .NET SDK in minutes
---

# .NET SDK Quick Start

Get started with the Rowland .NET SDK in minutes.

## Installation

```bash
dotnet add package Rowland.DocumentsApi.Sdk

Authentication

Get your API key from the Rowland dashboard and configure it:

var apiKey = "your-api-key-here"; var apiBaseUrl = "https://documents.rowland.ai";
# Set environment variable export ROWLAND_API_KEY="your-api-key"
var apiKey = Environment.GetEnvironmentVariable("ROWLAND_API_KEY");

Basic Usage

Initialize the Client

using DocumentsApi.Sdk.Clients;

var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("https://documents.rowland.ai");
var client = new DocumentsApiClient(httpClient, "your-api-key");

Upload a Document

try
{
    using var fileStream = File.OpenRead("lease_agreement.pdf");
    var document = await client.UploadDocumentAsync(
        fileStream,
        "lease_agreement.pdf"
    );
    
    Console.WriteLine($"Document uploaded successfully!");
    Console.WriteLine($"ID: {document.Id}");
    Console.WriteLine($"Status: {document.Status}");
}
finally
{
    httpClient.Dispose();
}
using var fileStream = File.OpenRead("lease_agreement.pdf");
var document = await client.UploadDocumentAsync(
    fileStream,
    "lease_agreement.pdf",
    userId: "user-123",
    organizationId: "org-456",
    folderId: "folder-789",
    webhookUrl: "https://yourapp.com/webhook",
    webhookSecret: "your-webhook-secret"
);

Console.WriteLine($"Document uploaded: {document.Id}");

Remember to dispose of the HttpClient when you're done, or use dependency injection in ASP.NET Core applications.

Check Processing Status

// Get document by ID
var document = await client.GetDocumentAsync("doc-123");
Console.WriteLine($"Status: {document.Status}");

switch (document.Status)
{
    case DocumentStatus.Success:
        Console.WriteLine("Document processing complete!");
        break;
    case DocumentStatus.Processing:
        Console.WriteLine("Still processing...");
        break;
    case DocumentStatus.Failed:
        Console.WriteLine("Processing failed");
        break;
    case DocumentStatus.Queued:
        Console.WriteLine("Queued for processing");
        break;
}

Get Extracted Data

if (document.Status == DocumentStatus.Success)
{
    var extractions = await client.GetDocumentExtractionsAsync(document.Id);

    Console.WriteLine($"Found {extractions.TotalObjectsFound} objects");
    Console.WriteLine($"Document: {extractions.DocumentName}");

    if (extractions.ConsolidatedObjects?.Any() == true)
    {
        foreach (var obj in extractions.ConsolidatedObjects)
        {
            Console.WriteLine($"Object data: {string.Join(", ", obj.Select(kv => $"{kv.Key}: {kv.Value}"))}");
        }
    }
}

List Documents

// Get recent documents
var documents = await client.GetDocumentsAsync(offset: 0, limit: 10);

Console.WriteLine($"Total documents: {documents.Total}");
Console.WriteLine($"Has next page: {documents.HasNext}");

foreach (var doc in documents.Items)
{
    Console.WriteLine($"• {doc.Name} ({doc.Status})");
    Console.WriteLine($"  Type: {doc.DocumentType}");
    Console.WriteLine($"  Created: {doc.CreatedAt?.ToString("yyyy-MM-dd HH:mm:ss")}");
}

Complete Example

Here's a complete working example that demonstrates all the main features:

using DocumentsApi.Sdk.Clients;

Console.WriteLine("Documents API SDK Example");
Console.WriteLine("========================");

var apiBaseUrl = "https://documents.rowland.ai";
var apiKey = "your-api-key-here"; // Replace with your actual API key

var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(apiBaseUrl);
var client = new DocumentsApiClient(httpClient, apiKey);

try
{
    // 1. Test health endpoint
    Console.WriteLine("1. Testing health endpoint...");
    var health = await client.GetHealthAsync();
    Console.WriteLine($"Health check: {health["status"]}");
    Console.WriteLine();

    // 2. Upload a document (uncomment to test)
    /*
    Console.WriteLine("2. Uploading a document...");
    using var fileStream = File.OpenRead("/path/to/your/document.pdf");
    var uploadedDoc = await client.UploadDocumentAsync(fileStream, "document.pdf");
    Console.WriteLine($"Uploaded: {uploadedDoc.Id} - {uploadedDoc.Name}");
    Console.WriteLine($"Status: {uploadedDoc.Status}, Type: {uploadedDoc.DocumentType}");
    */

    // 3. List documents
    Console.WriteLine("3. Fetching documents...");
    var documents = await client.GetDocumentsAsync(offset: 0, limit: 10);
    Console.WriteLine($"Found {documents.Total} total documents");

    if (documents.Items.Any())
    {
        var firstDoc = documents.Items.First();

        // 4. Get specific document
        Console.WriteLine($"4. Getting document: {firstDoc.Id}");
        var specificDoc = await client.GetDocumentAsync(firstDoc.Id);
        Console.WriteLine($"Retrieved: {specificDoc.Name}");

        // 5. Get extractions
        if (specificDoc.Status == DocumentStatus.Success)
        {
            Console.WriteLine("5. Getting extractions...");
            var extractions = await client.GetDocumentExtractionsAsync(firstDoc.Id);
            Console.WriteLine($"Found {extractions.TotalObjectsFound} objects");
        }
    }

    Console.WriteLine("All API methods tested successfully!");
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"HTTP Error: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}
finally
{
    httpClient.Dispose();
}

Error Handling

try
{
    var document = await client.GetDocumentAsync("doc-123");
}
catch (HttpRequestException ex) when (ex.Message.Contains("401"))
{
    Console.WriteLine("Unauthorized: Check your API key");
}
catch (HttpRequestException ex) when (ex.Message.Contains("404"))
{
    Console.WriteLine("Document not found");
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"HTTP Error: {ex.Message}");
}