Quaero.REST.Agent

Quaero.REST.Agent

Quaero.REST.Agent Class

public class Quaero.REST.Agent;
Quaero Archive REST API user agent.

Constructor

new Quaero.REST.Agent(System.String ep);
Build a REST API user agent. Note that the Agent sets a custom ServerCertificateValidationCallback. This might mess with other parts of your code. See [Quaero.REST.Agent.ssl_verification].

Parameters

ep
Optional base URL of the REST API. Generally something like https://quaero.local.lan/dw/v1/.
[System.String]

Example

// See REST API authentication.

ssl_verification() Static Method

System.Boolean Quaero.REST.Agent.ssl_verification(System.Object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors);
Handle custom SSL certificate validation. Quaero inc uses a custom CA root to issue SSL certificates to your Archive. This CA root is not part of the standard bundle installed by .Net. So we use this validation callback to make sure requests are made to a server with a certificate issued by the Quaero CA. See [System.Net.ServicePointManager.ServerCertificateValidationCallback].

Parameters

sender
An object that contains state information for this validation.
[System.Object]
certificate
The certificate used to authenticate the remote party.
[System.Security.Cryptography.X509Certificates.X509Certificate]
chain
The chain of certificate authorities associated with the remote certificate.
[System.Security.Cryptography.X509Certificates.X509Chain]
sslPolicyErrors
One or more errors associated with the remote certificate.
[System.Net.Security.SslPolicyErrors]

Returns

quaero_ca_create() Method

 Quaero.REST.Agent.quaero_ca_create();
Build Quaero Certificate Authority object, if it isn't already built.

ca_create() Method

 Quaero.REST.Agent.ca_create(System.IO.Stream stream);
Create a cert from a stream.

Parameters

stream
Stream to read the certificate from
[System.IO.Stream]

ca_create() Method

 Quaero.REST.Agent.ca_create(System.Byte[] raw);
Create a cert from a byte array.

Parameters

raw
The raw certificate data.
[System.Byte[]]

ca_create() Method

 Quaero.REST.Agent.ca_create(System.String filename);
Create a cert from a file.

Parameters

filename
Name of the file to load the cert from.
[System.String]

set_credentials() Method

void Quaero.REST.Agent.set_credentials(System.String tokenID, System.String secret);
Set the credentials used for authentication. The credentials are provided by the adminstrative tools, under Users.

Parameters

tokenID
Your user token.
[System.String]
secret
Your user secret.
[System.String]

set_endpoint() Method

void Quaero.REST.Agent.set_endpoint(System.String ep);
Set the base URL for all REST endpoints. For example "http://quaero.local.lan:33133/dw/v1"

Parameters

ep
Full text URL.
[System.String]

set_temp() Method

void Quaero.REST.Agent.set_temp(System.String t);
Set a temporary directory.

Parameters

t
[System.String]
System.String Quaero.REST.Agent.link_for(System.String rel);
Find the HATEOAS link for a given relationship. See REST API authentication for a list of all the possible relationships.

Parameters

rel
Name of the relationship.
[System.String]

Returns

System.String Quaero.REST.Agent.link_for(System.String rel, System.String name);
Get a HATEOAS link for a given object relationship. If you want the link for the TIFF format, you'd call link_for with rel="formats" and name="tif". See JSON rel for a list of all the possible relationships.

Parameters

rel
Name of the relationship.
[System.String]
name
Name of the object.
[System.String]

Returns

An URL
[System.String]
System.String Quaero.REST.Agent.link_for(System.String rel, Quaero.DW.UCriteria criteria);
Get a HATEOAS link for a given object relationship.

Parameters

rel
Name of the relationship. Currently only "documents" makes sense.
[System.String]
criteria
Criteria to search for.
[Quaero.DW.UCriteria]

Returns

An URL
[System.String]

Example

DW.UCriteria crit = new DW.UCriteria { { "invoice", "FF-123312" }, { "type", "01-invoices" } };
String url = agent.link_for( "documents", crit );

build_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.build_req(System.String path, Newtonsoft.Json.Linq.JObject data);
Build an HTTP request object

Parameters

path
URL or partial URL to the endpoint
[System.String]
data
(Optional) JObject to send
[Newtonsoft.Json.Linq.JObject]

Returns

Returns an HTTP request to the relevant REST endpoint configured with any authorisation tokens. [System.Net.Http.HttpRequestMessage].

build_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.build_req(System.String path, Quaero.DW.Request payload);
Build an HTTP request object from a [Quaero.DW.Request].

Parameters

path
URL or partial URL to the endpoint
[System.String]
payload
A [Quaero.DW.Request] object you want to send.
[Quaero.DW.Request]

Returns

Returns an HTTP request to the relevant REST endpoint configured with any authorisation tokens. [System.Net.Http.HttpRequestMessage].

build_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.build_req(System.String path, System.String json);
Build a new request object

Parameters

path
URL or partial URL
[System.String]
json
(Optional) JSON data to to send
[System.String]

Returns

Returns an HTTP request to the relevant REST endpoint configured with any authorisation tokens.
[System.Net.Http.HttpRequestMessage]

have_authorization() Method

System.Boolean Quaero.REST.Agent.have_authorization();
Returns true if the agent has been authenticated and authorized to access the REST API.

Returns

expires Property

System.DateTime (Quaero.REST.Agent)agent.expires;
A [System.DateTime] object for when the agent's authorisation will expire.

is_expired Property

System.Boolean (Quaero.REST.Agent)agent.is_expired;
Will be true if the agent's authorisation is expired.

is_authorized Property

System.Boolean (Quaero.REST.Agent)agent.is_authorized;
Will be true if the agent has authorisation and it is not expired.
System.Net.Http.HttpRequestMessage Quaero.REST.Agent.link_req(System.String rel, System.String json);
Build an REST request from the HATEOAS links the agent knows of.

Parameters

rel
Relationship you want to follow
[System.String]
json
Optional JSON data
[System.String]

Returns

Returns an HTTP request to the relevant REST endpoint configured with any authorisation tokens.
[System.Net.Http.HttpRequestMessage]

linked_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.linked_req(Quaero.DW.Links o, System.String rel, System.String json);
Build a REST request from a list of HATEOAS links.

Parameters

o
A REST object that has HATEOAS links.
[Quaero.DW.Links]
rel
The relationship you want to follow.
[System.String]
json
Optional JSON data.
[System.String]

Returns

fetch() Method

System.Net.Http.HttpResponseMessage Quaero.REST.Agent.fetch(Quaero.DW.Links o, System.String rel);

Parameters

o
[Quaero.DW.Links]
rel
[System.String]

Returns

fetch() Method

T Quaero.REST.Agent.fetch<T>(Quaero.DW.Links obj, System.String rel, System.String json);
Fetch a related object following a HATEOAS relationship.

Generic parameters

T
Any Quaero REST reply. Must be a subclass of [Quaero.DW.Reply]

Parameters

obj
An object with HATEOAS links
[Quaero.DW.Links]
rel
The relationship you are interested in.
[System.String]
json
Optional JSON data.
[System.String]

Returns

T a subclass of [Quaero.DW.Reply]

fetch() Method

T Quaero.REST.Agent.fetch<T, PT>(PT aggregate, System.String amember, System.String member, System.String name);
Fetch a details about an object from a endpoint that returns aggregate objects.

Generic parameters

T
The type of the object you are fetching. Must be a sub-class of [Quaero.DW.Links].
PT
The type of the aggregate object. Must be aa sub-class of [Quaero.DW.Aggregate].

Parameters

aggregate
Aggregate object
[PT]
amember
Name of a member of the aggregate object that is an array of T.
[System.String]
member
Name of a member of the object to match against.
[System.String]
name
What you are looking for.
[System.String]

Returns

An object of [``0] class.
T a subclass of [Quaero.DW.Links]

fetch() Method

T Quaero.REST.Agent.fetch<T, PT>(System.String amember, System.String name);
Fetch the details of one REST object, using known HATEOAS links.

Generic parameters

T
The type of the object you are fetching. Must be a sub-class of [Quaero.DW.Links].
PT
The type of the aggregate object. Must be aa sub-class of [Quaero.DW.Aggregate].

Parameters

amember
Relationship you want
[System.String]
name
The object name
[System.String]

Returns

T a subclass of [Quaero.DW.Reply]

do_req() Method

System.Net.Http.HttpResponseMessage Quaero.REST.Agent.do_req(System.Net.Http.HttpRequestMessage req);
Perform an HTTP request synchronously.

Parameters

req
HTTP request
[System.Net.Http.HttpRequestMessage]

Returns

do_req() Method

T Quaero.REST.Agent.do_req<T>(System.Net.Http.HttpRequestMessage req);
Perform a synchronous HTTP request and parse the JSON response. If you want to do asynchronous HTTP requests, you may create your own thread and call [Quaero.REST.Agent.parse_resp()] with the response object.

Generic parameters

T
Class of the object that should be in the JSON response

Parameters

req
HTTP request
[System.Net.Http.HttpRequestMessage]

Returns

A subclass of [Quaero.DW.Reply]
T a subclass of [Quaero.DW.Reply]

do_req() Method

T Quaero.REST.Agent.do_req<T, PT>(System.Net.Http.HttpRequestMessage req, System.String amember);
Fetch one object via the REST API. Fetching an object will return an aggregate object that only has a single object. In other words, (PT)reply.amember[0] is a of type T.

Generic parameters

T
Class of the object you are fetching.
PT
Class of the aggregate object in the reply.

Parameters

req
An HTTP request.
[System.Net.Http.HttpRequestMessage]
amember
Name of the data field in the aggregate object that is the reply.
[System.String]

Returns

T a subclass of [Quaero.DW.Reply]

parse_resp() Method

Newtonsoft.Json.Linq.JObject Quaero.REST.Agent.parse_resp(System.Net.Http.HttpResponseMessage resp);
Get any JSON data from an HTTP response

Parameters

resp
[System.Net.Http.HttpResponseMessage]

Returns

parse_resp() Method

T Quaero.REST.Agent.parse_resp<T>(System.Net.Http.HttpResponseMessage resp);
Parse JSON data and return a DW.Reply object or a superclass of it.

Generic parameters

T
Class of object that the REST endpoint has sent you.

Parameters

resp
An HTTP response
[System.Net.Http.HttpResponseMessage]

Returns

T a subclass of [Quaero.DW.Reply]

connect() Method

System.Boolean Quaero.REST.Agent.connect();
Get a REST access token

Returns

upload_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.upload_req(Quaero.DW.Links o, System.String rel, System.String src, System.String name);
Build a REST request that will upload a file. See REST API upload.

Parameters

o
HATEOAS links
[Quaero.DW.Links]
rel
Relationship.
[System.String]
src
Full filename of the file to be uploaded.
[System.String]
name
Name of file on the server. Optional; defaults to the base name of src.
[System.String]

Returns

upload_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.upload_req(Quaero.DW.Links o, System.String rel, Quaero.DW.Document doc);
Create an REST request to upload the information fields of one document.

Parameters

o
List of HATEOAS objects.
[Quaero.DW.Links]
rel
Relationship we are uploading to.
[System.String]
doc
The information fields we wish to upload. The returned REST request will send doc.meta to Quaero Archive..
[Quaero.DW.Document]

Returns

search_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.search_req(Quaero.DW.Search search);
Build an HTTP request that will search Quaero Archive for your documents. See REST API searches.

Parameters

search
This is what you are searching for.
[Quaero.DW.Search]

Returns

An HTTP request that you can then pass to do_req().
[System.Net.Http.HttpRequestMessage]

Example

using Quaero;
using System.Net.Http;

DW.Search search = new DW.Search ();
search.criteria.words = "hello world";
search.criteria.type = "contract";
HttpRequestMessage req = agent.search_req( search );

// Criteria can be implicitly cast to Search.
DW.Criteria crit = new DW.Criteria ();
crit.words = "pill box";
crit.type = "contract";
HttpRequestMessage req2 = agent.search_req( crit );        

document_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.document_req(System.String NUM);
Build an HTTP request that will fetch the named document from Quaero Archive. See REST API documents.

Parameters

NUM
The unique document number.
[System.String]

Returns

An HTTP request that you can then pass to do_req().
[System.Net.Http.HttpRequestMessage]

Example

using Quaero;
using System.Net.Http;

HttpRequestMessage req = agent.document_req( "TG00100" );
// You can may now access req as you would any other HTTP request.

document_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.document_req(System.String NUM, System.String rel);
Build an HTTP requestion to fetch something related to a document. This method will first do a REST request to find details of the document.

Parameters

NUM
The document's unique NUM.
[System.String]
rel
The name of the HATEOAS link you wish to fetch. /// See REST API HATEOAS.
[System.String]

Returns

An HTTP request that you can then pass to do_req().
[System.Net.Http.HttpRequestMessage]

document_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.document_req(System.String NUM, System.Int32 page);
Build an HTTP requestion to fetch ne rendered page of a document. This method will first do a REST request to find details of the document.

Parameters

NUM
The document's unique NUM.
[System.String]
page
Page number. The first page is 0.
[System.Int32]

Returns

An HTTP request that you can then pass to do_req().
[System.Net.Http.HttpRequestMessage]

document_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.document_req(Quaero.DW.Document doc, System.Int32 page);
Request one rendered page of a document.

Parameters

doc
DW.Document you've already fetched.
[Quaero.DW.Document]
page
Page number. The first page is 0.
[System.Int32]

Returns

An HTTP request that you can then pass to do_req().
[System.Net.Http.HttpRequestMessage]

document_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.document_req(Quaero.DW.UCriteria criteria);
Build an HTTP request that will fetch a single document from Quaero Archive based on your search criteria See REST API documents.

Parameters

criteria
Search criteria that will find a single document.
[Quaero.DW.UCriteria]

Returns

An HTTP request that you can then pass to do_req().
[System.Net.Http.HttpRequestMessage]

Example

DW.UCriteria crit = new DW.UCriteria { { "invoice", "FF-123312" }, { "type", "01-invoices" } };
HttpRequestMessage req = agent.document_req( crit );

fetch_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.fetch_req(System.String rel, System.String name);
Build an HTTP request that will fetch a named object. If you want the link for the TIFF format, you'd call link_for with rel="formats" and name="tif".

Parameters

rel
Name of the HATEOAS relationship for this object. See JSON rel for a list of possible relationships.
[System.String]
name
The name of the object.
[System.String]

Returns

Example

using Quaero;
using System.Net.Http;

HttpRequestMessage req = agent.fetch_req( "formats", "tif" );
// You can may now access req as you would any other HTTP request.

fetch_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.fetch_req(System.String rel, Quaero.DW.UCriteria criteria);
Build an HTTP request that will fetch document based on simple search criteria.

Parameters

rel
Name of the HATEOAS relationship for this object. Currently only "documents" makes sense.
[System.String]
criteria
Simple search criteria.
[Quaero.DW.UCriteria]

Returns

Example

using Quaero;
using System.Net.Http;

DW.UCriteria crit = new DW.UCriteria { { "invoice", "FF-123312" }, { "type", "01-invoices" } };
HttpRequestMessage req = agent.fetch_req( "documents", crit );
// You can may now access req as you would any other HTTP request.

close() Method

void Quaero.REST.Agent.close();
Close a batch

formats() Method

Quaero.DW.Formats Quaero.REST.Agent.formats();
Fetch a list of file formats

Returns

DW.Formats object
[Quaero.DW.Formats]

Example

// See REST API file formats.

format() Method

Quaero.DW.Format Quaero.REST.Agent.format(System.String name);
Fetch details of one file format

Parameters

name
The name of the format, for example "pdf" or "docx"
[System.String]

Returns

One DW.Format object
[Quaero.DW.Format]

Example

// See REST API file formats.

types() Method

Quaero.DW.Types Quaero.REST.Agent.types();
Fetch the list of all document types

Returns

Example

// See REST API document types.

doc_type() Method

Quaero.DW.DocType Quaero.REST.Agent.doc_type(System.String name);
Fetch details of one document type

Parameters

name
The name of the document type.
[System.String]

Returns

Example

// See REST API document types.

fields() Method

Quaero.DW.Fields Quaero.REST.Agent.fields();
Fetch a list of all information fields

Returns

Example

// See REST API information fields.

info_field() Method

Quaero.DW.InfoField Quaero.REST.Agent.info_field(System.String name);
Fetch details of one information field.

Parameters

name
[System.String]

Returns

Example

// See REST API information fields.

queues() Method

Quaero.DW.Queues Quaero.REST.Agent.queues();
Fetch list of all document queues

Returns

Example

// See REST API processing queues.

queue() Method

Quaero.DW.Queue Quaero.REST.Agent.queue(System.String name);
Fetch details of one document queue.

Parameters

name
Name of the document queue, for example "incoming" or "aiguillage".
[System.String]

Returns

Example

// See REST API processing queues.

scanners() Method

Quaero.DW.Scanners Quaero.REST.Agent.scanners();
Fetch list of all scanner queues.

Returns

Example

// See REST API processing queues.

scanner() Method

Quaero.DW.Queue Quaero.REST.Agent.scanner(System.String name);
Fetch details of one scanner queue.

Parameters

name
Name of the queue, for instance "todo".
[System.String]

Returns

Example

// See REST API processing queues.

sequences() Method

Quaero.DW.Sequences Quaero.REST.Agent.sequences();
Fetch list of all sequences.

Returns

Example

// See REST API sequences.

sequence() Method

Quaero.DW.Sequence Quaero.REST.Agent.sequence(System.String name);
Fetch the next value from one sequence.

Parameters

name
Name of the sequence, for instance "DOC0000".
[System.String]

Returns

Example

// See REST API sequences.

Quaero.DW.SearchResults Quaero.REST.Agent.search(Quaero.DW.Search search);
Search Quaero Archive.

Parameters

search
Your search criteria.
[Quaero.DW.Search]

Returns

A list of documents [Quaero.DW.SearchResults].

Example

// See REST API searches.

document() Method

Quaero.DW.Document Quaero.REST.Agent.document(System.String NUM);
Fetch one document from Quaero Archive.

Parameters

NUM
Unique document number.
[System.String]

Returns

A single [Quaero.DW.Document].

Example

// See REST API documents.

document() Method

System.Net.Http.HttpResponseMessage Quaero.REST.Agent.document(Quaero.DW.Document doc, System.String rel);
Fetch something related to a document.

Parameters

doc
The document you've alread fetched.
[Quaero.DW.Document]
rel
The name of the HATEOAS link you wish to fetch. See REST API HATEOAS.
[System.String]

Returns

Example

// See also REST API / Fetch one document file.

document() Method

Quaero.DW.Document Quaero.REST.Agent.document(Quaero.DW.UCriteria criteria);
Fetch one document from Quaero Archive based on search criteria

Parameters

criteria
Unique document number.
[Quaero.DW.UCriteria]

Returns

A single [Quaero.DW.Document].

Example

DW.UCriteria crit = new DW.UCriteria { { "invoice", "FF-123312" }, { "type", "01-invoices" } };
DW.Document doc = agent.document( crit );
// See also REST API / Fetching the information about one document.

file() Method

System.Net.Http.HttpResponseMessage Quaero.REST.Agent.file(System.String NUM, System.String rel);
Fetch a file related to a document. This method will do 2 REST requests, the first one to fetch document details and the second one to fetch the file.

Parameters

NUM
The document's unique NUM.
[System.String]
rel
The name of the HATEOAS link you wish to fetch. See REST API HATEOAS.
[System.String]

Returns

Example

// See REST API / Fetch one document file.

file() Method

System.Net.Http.HttpResponseMessage Quaero.REST.Agent.file(Quaero.DW.Document doc, System.String rel);
Fetch a file related to a document.

Parameters

doc
A DW.Document object previously fetched.
[Quaero.DW.Document]
rel
The name of the HATEOAS link you wish to fetch. See REST API HATEOAS.
[System.String]

Returns

Example

// See REST API / Fetch one document file.

file() Method

System.Net.Http.HttpResponseMessage Quaero.REST.Agent.file(System.String NUM, System.Int32 page);
Fetch the prerendered PNG of a one page of the document. This method will do 2 REST requests, the first one to fetch document details and the second one to fetch the file.

Parameters

NUM
The document's unique NUM.
[System.String]
page
The page number. Page numbers start at 0.
[System.Int32]

Returns

Example

// See REST API / Fetch one document file.

file() Method

System.Net.Http.HttpResponseMessage Quaero.REST.Agent.file(Quaero.DW.Document doc, System.Int32 page);
Fetch the prerendered PNG of a one page of the document.

Parameters

doc
A DW.Document object previously fetched.
[Quaero.DW.Document]
page
The page number. Page numbers start at 0.
[System.Int32]

Returns

Example

// See REST API / Fetch one document file.

delete_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.delete_req(System.String NUM);
Build a request to delete a document from the archive.

Parameters

NUM
The document's unique NUM.
[System.String]

Returns

Example

// See REST API / Delete a document.

delete_req() Method

System.Net.Http.HttpRequestMessage Quaero.REST.Agent.delete_req(Quaero.DW.Document doc);
Build a request to delete a document from the archive.

Parameters

doc
A DW.Document object.
[Quaero.DW.Document]

Returns

A request you can pass to do_req().
[System.Net.Http.HttpRequestMessage]

Example

// See REST API / Delete a document.

delete() Method

Quaero.DW.Document Quaero.REST.Agent.delete(System.String NUM);
Delete a document from the archive.

Parameters

NUM
The document's unique NUM.
[System.String]

Returns

Returns details of the document if the request was successful.
[Quaero.DW.Document]

Example

// See REST API / Delete a document.

delete() Method

Quaero.DW.Document Quaero.REST.Agent.delete(Quaero.DW.Document doc);
Delete a document from the archive.

Parameters

doc
A DW.Document object.
[Quaero.DW.Document]

Returns

Returns details of the document if the request was successful.
[Quaero.DW.Document]

Example

// See REST API / Delete a document.