The WFD.Abbyy.Api.Core library allows for interaction with the ABBYY Cloud rest API through a set of standard methods. This DLL is also consumed by the WFD.Abbyy.Api REST API that can be deployed using Azure Dev Ops.
Any interactions with the ABBYY Cloud for Invoices API should run through this library
Usage
All methods to interact with ABBYY cloud take a DatasetContext as part of the parameters. Before running any interactions a new DatasetContext instance should first be initialized and the Connect() method ran. using (var datasetContext = new DatasetContext()) { var connectionResponse = datasetContext.Connect(Settings.Default.Region, Settings.Default.AbbyyEndpointUrl, Settings.Default.AbbyyUsername, Settings.Default.AbbyyPassword, Settings.Default.ProjectName, Settings.Default.DocDefName);
if (connectionResponse.Status == ResponseStatus.OK){
//Your code here
}
}
The DatasetContext object is a standard implementation used by both the Disti and Cloud connections. For that reason, the ProjectName & DocDefName parameters are not required for connecting to ABBYY Cloud
Datasets
Once a DatasetContext has been initialized a new DatasetWrapper object should be created. The DatasetWrapper object then has a set of methods to allow for all CRUD operations with the ABBYY cloud datasets.
var wrapper = new DatasetWrapper();
var results = wrapper.Get(datasetContext, "BusinessUnits", new Dictionary(), 1000);
foreach (var result in results.Data) { foreach (var field in result.Fields) { System.Console.WriteLine($"{field.FieldName} - {field.FieldValue}"); } }
`Important - ABBYY Cloud For Invoices only has two datasets: BusinessUnits & Vendors. Any calls made that aren't for a dataset with either of these two names will fail
Create/Update
When creating or updating records fields are passed in as a Dictionary where the key is the field name and the value is the field value. var records = new List>(); var record1 = new Dictionary(); record1.Add("Id", "1"); record1.Add("Name", "My Test Record"); records.Add(record1); wrapper.Add(datasetContext, "BusinessUnits", records);
Recognition Tasks
You can also send recognition tasks to ABBYY Cloud using a TaskWrapper object. Once a task has been sent the status of the task can then be returned using the Get method of a TaskWrapper
var taskWrapper = new TaskWrapper();
var files = new Dictionary(); files.Add(@"C:\myfile.pdf", File.ReadAllBytes("C:\myfile.pdf")); files.Add(@"C:\mysecondfile.pdf", File.ReadAllBytes("C:\mysecondfile.pdf"));
var uploadResponse = taskWrapper.UploadDocumentsAndStartTask(datasetContext, files);
System.Console.WriteLine(uploadResponse.Data.TaskId);
var taskStatus = taskWrapper.Get(datasetContext, uploadResponse.Data.TaskId);
System.Console.WriteLine(taskStatus.Data.Status);