com.hyperscience.saas
1.0.14
Prefix Reserved
dotnet add package com.hyperscience.saas --version 1.0.14
NuGet\Install-Package com.hyperscience.saas -Version 1.0.14
<PackageReference Include="com.hyperscience.saas" Version="1.0.14" />
<PackageVersion Include="com.hyperscience.saas" Version="1.0.14" />
<PackageReference Include="com.hyperscience.saas" />
paket add com.hyperscience.saas --version 1.0.14
#r "nuget: com.hyperscience.saas, 1.0.14"
#:package com.hyperscience.saas@1.0.14
#addin nuget:?package=com.hyperscience.saas&version=1.0.14
#tool nuget:?package=com.hyperscience.saas&version=1.0.14
Hyperscience SaaS Client Library
With the Hyperscience SaaS client library, you can authenticate to SaaS instances of Hyperscience and make API requests. The library supports the following frameworks:
- .NET Framework 4.6.1 or above
- .NET and .NET Core 2.0 or above
Quickstart Guide
1. Set up API credentials
Retrieve your API credentials from your Hyperscience SaaS instance. To learn more, see API Access for SaaS Instances.
2. Configure authentication parameters
You can configure the authentication parameters using the ApiController. The ApiController uses a Configuration object. This object includes data about the following:
- Hyperscience's domain to make the requests to (
hs_domain) - mandatory - Authentication domain (
auth_server) - optional, defaults tologin.hyperscience.net - Timeout configuration in seconds (
timeout_configuration) - optional, defaults toconnection_timeout: 60andread_timeout: 60
This is a JSON example for the configuration (you should set the hs_domain value):
{
"hs_domain": "hs_instance.hyperscience.net",
"auth_server": "login.hyperscience.net",
"timeout_configuration": {
"connection_timeout": 60,
"read_timeout": 60
}
}
You can set your Configuration object in one of the following three ways.
From a JSON string
string jsonString = $@"
{{
""auth_server"" : ""login.hyperscience.net"",
""hs_domain"" : ""tpi-dev.hyperscience.net"",
""request_timeout_in_seconds"" : 180
}}";
var configuration = Hyperscience.Saas.Config.Configuration.FromJsonString(jsonString);
From a JSON file
var configuration = Hyperscience.Saas.Config.Configuration.FromJsonFile("/full/path/to/Config.json");
At object instantiation
var configuration = new Hyperscience.Saas.Config.Configuration("<Hyperscience_URL>");
// or
var configuration = new Hyperscience.Saas.Config.Configuration("<Hyperscience_URL>", "login.hyperscience.net");
3. Provide Credentials
There are two options for providing credentials:
a. Environment Variables (Recommended)
To use environment variables to store your credentials, follow the steps below:
- Put your
client_idin an.envfile variable calledHS_CLIENT_ID. - Put the
client_secretin an.envfile variable calledHS_CLIENT_SECRET.
Then, these credentials will be loaded from environment variables if the ApiController class is instantiated as:
var configuration = new Configuration("<Hyperscience_URL>");
//Implicitly
var apiController = new ApiController(configuration);
//Or Explicitly
var apiController = new ApiController(configuration, new EnvironmentCredentialsProvider());
b. In code using an instance of CredentialsProvider
var credentials = new CredentialsProvider("<clientid>", "<clientsecret>");
var apiController = new ApiController(configuration, credentials);
We strongly recommend against storing your credentials in code. Instead, we recommended calling out to an
external, secure service to fill in the client_id and client_secret variables.
4. Make a Test Call
Ensure that your setup is correct by making a test call to GET submissions from your instance.
var configuration = new Configuration("<Hyperscience_URL>");
CredentialsBase credentials = new CredentialsProvider("<client_id>", "<client_secret>");
ApiController _apiController = new ApiController(configuration, credentials);
var httpResponseMessage = _apiController.Get("/api/v5/submissions");
Console.WriteLine(httpResponseMessage.ToString());
Console.WriteLine(httpResponseMessage.Content.ReadAsStringAsync().Result);
Using the ApiController
The ApiController allows users to interact with the Hyperscience API by utilizing wrapper methods.
To learn more, see Hyperscience’s API documentation.
Supported Methods
The ApiController supports GET, POST, and PUT operations, with both synchronous and
asynchronous versions of them.
Synchronous functions return a HttpResponseMessage and are named:
GetPostPut
Asynchronous functions return a Task<HttpResponseMessage> and are named:
GetAsyncPostAsyncPutAsync
You can find more information about asynchronous execution here.
Parameters for these operations (query params, encoded url parameters, or files input) can be provided by a
Collection that implements IEnumarable<KeyValuePair<string, string>>`. You can use either one of the
approaches below:
Dictionary<string, string>- if duplicate keys are not neededList<KeyValuePair<string, string>>- if duplicate keys are needed
Examples
Configuration and Setup
using System.Net.Http;
using Hyperscience.Saas.Config;
using Hyperscience.Saas.Service.Api;
using Hyperscience.Saas.Service.Api.Enum;
using Hyperscience.Saas.Service.Auth.Model.Credentials;
var configuration = new Configuration("<Hyperscience_URL>");
var credentials = new Credentials("<clientid>", "<clientsecret>");
var apiController = new ApiController(configuration, credentials);
GET Submissions
var httpResponseMessage = _apiController.Get("/api/v5/submissions");
Console.WriteLine(httpResponseMessage.ToString());
Console.WriteLine(httpResponseMessage.Content.ReadAsStringAsync().Result);
POST a New Submission Using UrlEncoded Content Type
var duplicateKeysAllowed = new List<KeyValuePair<string, string>>();
duplicateKeysAllowed.Add(new KeyValuePair<string, string>("file", "s3://path/to/file.jpg"));
duplicateKeysAllowed.Add(new KeyValuePair<string, string>("file", "https://host/path/to/file2.jpg"));
// If no payload type is passed, it defaults to DataSupportedContentType.UrlEncoded
var httpResponseMessage = apiController.Post(
"/api/v5/submissions", duplicateKeysAllowed
);
// Or explicitely defining the payload as DataSupportedContentType.UrlEncoded
httpResponseMessage = apiController.Post(
"/api/v5/submissions", duplicateKeysAllowed, DataSupportedContentType.UrlEncoded
);
POST a New Submission Using MultipartFormData Content Type
var filesDictionary = new Dictionary<string, string>();
filesDictionary.Add("file", "/absolute/path/to/file/demo-long.pdf");
var httpResponseMessage = apiController.Post(
"/api/v5/submissions", filesDictionary, DataSupportedContentType.MultipartFormData
);
POST a New Submission Using ApplicationJSON Content Type
Although the general recommendation is to use MultipartFormData as content type because it is possible
to send large documents if needed, JSON payloads are also supported by Hyperscience's API. Details about
the format of the payload can be found in
Hyperscience's API documentation.
Given the following JSON file:
{
"metadata": null,
"machine_only": true,
"goal_duration_minutes": 5,
"single_document_per_page": true,
"restrictions": [],
"source_routing_tags": [
"tag1",
"tag2"
],
"files": [
{
"file_content_base64": "data:image/png;base64,iVBORw0KGgA ... <base64encodedFile> ... CYII=",
"filename": "image.png"
}
],
"cases": [
{
"external_case_id": "case_1",
"filenames": [
"image.png"
]
}
]
}
Load the file into memory and send it as a dictionary:
string jsonContent = System.IO.File.ReadAllText(@"<file_path>");
dynamic jsonObject = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonContent);
var httpResponseMessage = _apiController.Post(
"/api/v5/submissions", jsonObject, PayloadSupportedContentType.ApplicationJson
);
Obtaining Response's Content
Regardless whether the request is made synchronously or asynchronously, obtaining HttpResponseMessage's
content as a string requires calling ReadAsStringAsync, which returns a Task<string> object.
Console.WriteLine(httpResponseMessage.Content.ReadAsStringAsync().Result);
Logging
The Hyperscience SaaS client library uses Serilog for logging purposes. To learn more about Serilog, see the Serilog.Settings.Configuration documentation on the GitHub website.
The library comes with a default configuration that has the log level setting set to “Information”. To override this setting, add the appsetting.json configuration file to your project. In your IDE, make sure to set the Copy to output directory setting to “Always”.
Sample appsetting.json configuration file
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{ "Name": "File", "Args": { "path": "Logs/log.txt" } }
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Destructure": [
{ "Name": "ToMaximumDepth", "Args": { "maximumDestructuringDepth": 4 } },
{ "Name": "ToMaximumStringLength", "Args": { "maximumStringLength": 100 } },
{ "Name": "ToMaximumCollectionCount", "Args": { "maximumCollectionCount": 10 } }
],
"Properties": {
"Application": "Sample"
}
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- Microsoft.Extensions.Configuration (>= 2.0.0)
- Microsoft.Extensions.Configuration.Json (>= 2.0.0)
- NewtonSoft.Json (>= 13.0.3)
- Serilog (>= 2.7.1)
- Serilog.Enrichers.Environment (>= 2.1.1)
- Serilog.Enrichers.Thread (>= 3.0.0)
- Serilog.Settings.Configuration (>= 3.0.0)
- Serilog.Sinks.Console (>= 3.1.0)
- Serilog.Sinks.File (>= 3.2.0)
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 2.0.0)
- Microsoft.Extensions.Configuration.Json (>= 2.0.0)
- NewtonSoft.Json (>= 13.0.3)
- Serilog (>= 2.7.1)
- Serilog.Enrichers.Environment (>= 2.1.1)
- Serilog.Enrichers.Thread (>= 3.0.0)
- Serilog.Settings.Configuration (>= 3.0.0)
- Serilog.Sinks.Console (>= 3.1.0)
- Serilog.Sinks.File (>= 3.2.0)
-
.NETStandard 2.1
- Microsoft.Extensions.Configuration (>= 2.0.0)
- Microsoft.Extensions.Configuration.Json (>= 2.0.0)
- NewtonSoft.Json (>= 13.0.3)
- Serilog (>= 2.7.1)
- Serilog.Enrichers.Environment (>= 2.1.1)
- Serilog.Enrichers.Thread (>= 3.0.0)
- Serilog.Settings.Configuration (>= 3.0.0)
- Serilog.Sinks.Console (>= 3.1.0)
- Serilog.Sinks.File (>= 3.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.14 | 543 | 9/11/2025 |
| 1.0.13 | 898 | 4/15/2025 |
| 1.0.12 | 2,877 | 8/29/2024 |
| 1.0.11 | 1,042 | 11/20/2023 |
| 1.0.11-alpha.2 | 115 | 11/7/2023 |
| 1.0.11-alpha.1 | 118 | 11/1/2023 |
| 1.0.10 | 7,944 | 1/23/2023 |
| 1.0.9 | 658 | 12/15/2022 |
| 1.0.8 | 4,558 | 7/11/2022 |
| 1.0.7 | 885 | 4/27/2022 |
| 1.0.7-alpha.2 | 249 | 4/21/2022 |
| 1.0.7-alpha.1 | 242 | 4/20/2022 |
| 1.0.6 | 1,027 | 2/9/2022 |
| 1.0.5 | 728 | 2/3/2022 |
| 1.0.4 | 664 | 1/4/2022 |
| 1.0.3 | 2,315 | 12/16/2021 |
| 1.0.2 | 455 | 12/8/2021 |
| 1.0.1 | 465 | 11/22/2021 |
| 1.0.0.1 | 592 | 10/28/2021 |