SDK Installation

NuGet

To add the NuGet package to a .NET project:

dotnet add package ABBYY.DocumentAI

Locally

To add a reference to a local instance of the SDK in a .NET project:

dotnet add reference src/ABBYY/DocumentAI/ABBYY.DocumentAI.csproj

SDK Example Usage

Example

using ABBYY.DocumentAI;
using ABBYY.DocumentAI.Schemas.Components;
using ABBYY.DocumentAI.Schemas.Requests;

var sdk = new DocumentAI(apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>");

ListDocumentsResponse? res = await sdk.Documents.ListAsync(
    cursor: "<optional_pagination_cursor_goes_here>",
    limit: 10
);

while(res != null)
{
    // handle items

    res = await res.Next!();
}

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

NameTypeScheme
ApiKeyAuthhttpHTTP Bearer

To authenticate with the API the ApiKeyAuth parameter must be set when initializing the SDK client instance. For example:

using ABBYY.DocumentAI;
using ABBYY.DocumentAI.Schemas.Components;
using ABBYY.DocumentAI.Schemas.Requests;

var sdk = new DocumentAI(apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>");

ListDocumentsResponse? res = await sdk.Documents.ListAsync(
    cursor: "<optional_pagination_cursor_goes_here>",
    limit: 10
);

while(res != null)
{
    // handle items

    res = await res.Next!();
}

Available Resources and Operations

The available API operations and SDK implementation examples can be found within our API Reference documentation

Pagination

Some of the endpoints in this SDK support pagination. To use pagination, you make your SDK calls as usual, but the returned response object will have a Next method that can be called to pull down the next group of results. If the return value of Next is null, then there are no more pages to be fetched.

Here’s an example of one such pagination call:

using ABBYY.DocumentAI;
using ABBYY.DocumentAI.Schemas.Components;
using ABBYY.DocumentAI.Schemas.Requests;

var sdk = new DocumentAI(apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>");

ListDocumentsResponse? res = await sdk.Documents.ListAsync(
    cursor: "<optional_pagination_cursor_goes_here>",
    limit: 10
);

while(res != null)
{
    // handle items

    res = await res.Next!();
}

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default, an API error will raise a ABBYY.DocumentAI.Schemas.Errors.APIException exception, which has the following properties:

PropertyTypeDescription
MessagestringThe error message
RequestHttpRequestMessageThe HTTP request
ResponseHttpResponseMessageThe HTTP response

When custom error responses are specified for an operation, the SDK may also throw their associated exceptions. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the ListAsync method throws the following exceptions:

Error TypeStatus CodeContent Type
ABBYY.DocumentAI.Schemas.Errors.BadRequestError400application/json
ABBYY.DocumentAI.Schemas.Errors.UnauthorizedError401application/json
ABBYY.DocumentAI.Schemas.Errors.TooManyRequestsError429application/json
ABBYY.DocumentAI.Schemas.Errors.InternalServerError500application/json
ABBYY.DocumentAI.Schemas.Errors.APIException4XX, 5XX*/*

Example

using ABBYY.DocumentAI;
using ABBYY.DocumentAI.Schemas.Components;
using ABBYY.DocumentAI.Schemas.Errors;
using ABBYY.DocumentAI.Schemas.Requests;

var sdk = new DocumentAI(apiKeyAuth: "<YOUR_BEARER_TOKEN_HERE>");

try
{
    ListDocumentsResponse? res = await sdk.Documents.ListAsync(
        cursor: "<optional_pagination_cursor_goes_here>",
        limit: 10
    );

    while(res != null)
    {
        // handle items

        res = await res.Next!();
    }
}
catch (Exception ex)
{
    if (ex is BadRequestError)
    {
        // Handle exception data
        throw;
    }
    else if (ex is UnauthorizedError)
    {
        // Handle exception data
        throw;
    }
    else if (ex is TooManyRequestsError)
    {
        // Handle exception data
        throw;
    }
    else if (ex is InternalServerError)
    {
        // Handle exception data
        throw;
    }
    else if (ex is ABBYY.DocumentAI.Schemas.Errors.APIException)
    {
        // Handle default exception
        throw;
    }
}