The javascript SDK for the Onspring API is meant to simplify development in Javascript 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 their existing C# SDK, their swagger page, and api documentation as the starting point with the intention of making development of integrations done in Javascript with an Onspring instance quicker and more convenient.
All methods for the `OnspringClient` make use of the [Axios](https://axios-http.com/) http client to interact with the Onspring API.
### Form-Data
When it is necessary to send requests to the Onspring API using `multi-part/form-data` the [Form-Data](https://www.npmjs.com/package/form-data) package is used.
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.
## Start Coding
### `OnspringClient`
The most common way to use the SDK is to create an `OnspringClient` instance and call its methods. Its constructor requires two parameters:
-`baseUrl` - currently this should always be: `https://api.onspring.com`
-`apiKey` - the value obtained by following the steps in the **API Key** section
It is best practice to read these values in from a configuration file for both flexibility and security purposes.
By default when you construct an instance of the `OnspringClient` the a new `Axios` instance will also be created. Its `baseURL` property will always be set to the `baseUrl` parameter based to the `OnspringClient`'s constructor and its headers will always contain the proper `x-api-key` header.
You can though pass a third optional argument to the `OnspringClient` constructor that specifies additional configuration options for the `Axios` instance used to make requests.
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.
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.
```js
```
#### Get Record By Id
Returns an onspring record based on the provided app and record ids.
```js
```
You can also specify what field values to return and in what format (Raw vs. Formatted) to return them.
```js
```
#### Get Records By Ids
Returns a collection of Onspring records based on the provided appId and recordIds.
```js
```
You can also specify 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.
```js
```
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 v2 of 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.
```js
```
You can update a record by providing its id. If successful will return the id of record updated.
```js
```
#### Delete Records By Ids
```js
```
### Reports
#### Get Report By Id
Returns the report for the provided id.
```js
```
You can also specify the format of the data in the report as well as whether you are requesting the report's data or its chart data.
```js
```
#### Get Reports By App Id
Returns a paged collection of reports that can be paged through. By default the page size is 50 and page number is 1.