The Rust SDK for the Onspring API is meant to simplify development in Rust for Onspring customers who want to build integrations with their Onspring instance.
**Note:** This is an unofficial SDK for the Onspring API. It was not built in consultation with Onspring Technologies LLC or a member of their development team.
This SDK was developed independently using Onspring's existing [C# SDK](https://github.com/onspring-technologies/onspring-api-sdk), the Onspring API's [swagger page](https://api.onspring.com/swagger/index.html), and [API documentation](https://software.onspring.com/hubfs/Training/Admin%20Guide%20-%20v2%20API.pdf) as the starting point with the intention of making development of integrations done in Rust with an Onspring instance quicker and more convenient.
## Dependencies
### Rust
Requires Rust edition 2021 or later (Rust 1.56+).
### Key Crates
| Crate | Purpose |
|-------|---------|
| [reqwest](https://crates.io/crates/reqwest) | HTTP client for all API requests |
| [serde](https://crates.io/crates/serde) / [serde_json](https://crates.io/crates/serde_json) | JSON serialization and deserialization |
| [chrono](https://crates.io/crates/chrono) | Date and time types |
| [uuid](https://crates.io/crates/uuid) | UUID types for list item identifiers |
| [thiserror](https://crates.io/crates/thiserror) | Error type derivation |
## Installation
Add the SDK to your project using Cargo:
```sh
cargo add onspring
```
Or add it directly to your `Cargo.toml`:
```toml
[dependencies]
onspring="0.1"
tokio={version="1",features=["full"]}
```
## API Key
In order to successfully interact with the Onspring API you will need an API key. API keys are obtained by an Onspring user with permissions to at least **Read** API Keys for your instance via the following steps:
1. Login to the Onspring instance.
2. Navigate to **Administration** > **Security** > **API Keys**.
3. On the list page, add a new API Key - this will require **Create** permissions - or click an existing API key to view its details.
4. Click on the **Developer Information** tab.
5. Copy the **X-ApiKey Header** value from this tab.
**Important:**
- An API Key must have a status of `Enabled` in order to make authorized requests.
- Each API Key must have an assigned Role. This role controls the permissions for requests made. If the API Key used does not have sufficient permissions the requests made won't be successful.
### Permission Considerations
You can think of any API Key as another user in your Onspring instance and therefore it is subject to all the same permission considerations as any other user when it comes to its ability to access data in your instance. The API Key you use needs to have all the correct permissions within your instance to access the data requested. Things to think about in this context are `role security`, `content security`, and `field security`.
## Start Coding
### `OnspringClient`
The most common way to use the SDK is to create an `OnspringClient` instance and call its methods. The builder requires an API key and defaults to `https://api.onspring.com` as the base URL.
It is best practice to read these values in from environment variables or a configuration file for both flexibility and security purposes.
By default when you construct an instance of the `OnspringClient` a new `reqwest::Client` will also be created with a 120-second timeout. You can customize the timeout or provide your own `reqwest::Client`:
All client methods return `onspring::Result<T>`, which is an alias for `Result<T, OnspringError>`. The `OnspringError` enum has the following variants:
-`Http` - An HTTP transport error occurred (network issues, timeouts, etc.).
-`Api { status_code, message }` - The API returned a non-success status code.
-`Serialization` - A JSON serialization or deserialization error occurred.
-`InvalidArgument` - An invalid argument was provided to an SDK method.
You may wish to refer to the full [Onspring API documentation](https://software.onspring.com/hubfs/Training/Admin%20Guide%20-%20v2%20API.pdf) when determining which values to pass as parameters to some of the `OnspringClient` methods. There is also a [swagger page](https://api.onspring.com/swagger/index.html) that you can use for making exploratory requests.
## Examples
Note the following code snippets assume you've already instantiated an `OnspringClient` as shown in the [OnspringClient](#onspringclient) section and that the code is running within an async context.
### Connectivity
#### Verify connectivity
```rust
client.ping().await?;
println!("Connected to Onspring API");
```
### Apps
#### Get Apps
Returns a paged collection of apps and/or surveys that can be paged through. By default the page size is 50 and page number is 1.
You can set your own page size and page number (max is 1,000) as well. In addition to specifying what field values to return and in what format (Raw vs. Formatted) to return them.
You can set your own page size and page number (max is 1,000) as well. In addition to specifying what field values to return and in what format (Raw vs. Formatted) to return them.
For further details on constructing the `filter` parameter please refer to the [documentation](https://software.onspring.com/hubfs/Training/Admin%20Guide%20-%20v2%20API.pdf) for the Onspring API.
#### Add or Update A Record
You can add a record by not providing a record id value. If successful will return the id of the added record.