2022-05-02 15:34:55 -05:00
# Onspring API Python SDK
2022-05-02 15:36:56 -05:00
The python SDK for **version 2** of the Onspring API is meant to simplify development in Python for Onspring customers who want to build integrations with their Onspring instance.
2022-05-02 15:34:55 -05:00
2022-05-03 08:56:47 -05:00
**Note:**
2022-05-03 08:57:24 -05:00
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.
2022-05-03 08:56:47 -05:00
2022-08-05 11:46:44 -05:00
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 Python with an Onspring instance quicker and more convenient.
2022-05-03 08:56:47 -05:00
2022-05-03 09:00:26 -05:00
## Dependencies
2022-05-03 09:40:19 -05:00
### Python
2023-01-25 11:35:25 -06:00
Requires use of Python 3.10.0 or later.
2022-05-03 09:40:19 -05:00
2026-06-26 17:43:30 -05:00
### httpx
2022-05-03 09:40:19 -05:00
2026-06-26 17:43:30 -05:00
All methods for `OnspringClient` and `AsyncOnspringClient` make use of the [httpx ](https://www.python-httpx.org/ ) library to interact with the endpoints of version 2 of the Onspring API.
2022-05-03 09:37:14 -05:00
2022-05-02 15:34:55 -05:00
## Installation
2022-05-02 15:36:16 -05:00
Install the SDK using pip:
2022-05-02 15:34:55 -05:00
2022-05-04 11:58:16 -05:00
`pip install OnspringApiSdk`
2022-05-02 15:34:55 -05:00
## 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.
## Start Coding
2022-05-03 09:00:26 -05:00
### `OnspringClient`
2022-05-03 09:00:55 -05:00
The most common way to use the SDK is to create an `OnspringClient` instance and call its methods. Its constructor requires two parameters:
2022-05-02 15:34:55 -05:00
2026-06-26 17:43:30 -05:00
- `url` - currently this should always be: `https://api.onspring.com`
- `key` - the value obtained by following the steps in the **API Key** section
2022-05-02 15:34:55 -05:00
It is best practice to read these values in from a configuration file for both flexibility and security purposes.
2022-05-02 16:31:26 -05:00
Example `config.ini` file:
2022-05-02 15:34:55 -05:00
2022-05-02 16:22:06 -05:00
```ini
2022-05-02 16:20:47 -05:00
[prod]
key = 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000
url = https://api.onspring.com
```
Example constructing `OnspringClient` :
2022-05-02 16:22:06 -05:00
2022-05-02 16:29:34 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk import OnspringClient
2022-05-02 15:34:55 -05:00
from configparser import ConfigParser
cfg = ConfigParser ()
cfg . read ( 'config.ini' )
key = cfg [ 'prod' ][ 'key' ]
url = cfg [ 'prod' ][ 'url' ]
client = OnspringClient ( url , key )
```
2026-06-26 17:43:30 -05:00
### `AsyncOnspringClient`
An async client is also available for use with `asyncio` :
```python
from onspring_api_sdk import AsyncOnspringClient
async with AsyncOnspringClient ( url , key ) as client :
response = await client . get_apps ()
```
All methods mirror the sync client with `await` prefixed.
2022-05-03 09:00:26 -05:00
### `ApiResponse`
2026-06-26 17:43:30 -05:00
Each client method returns an `ApiResponse` object with the following properties:
2022-05-03 10:50:34 -05:00
2026-06-26 17:43:30 -05:00
- `status_code` - The http status code of the response.
- `is_successful` - Whether the request was successful (status < 400).
- `data` - If the request was successful will contain the response data deserialized to Pydantic models.
2022-05-03 10:50:34 -05:00
- `message` - A message that may provide more detail about the requests success or failure.
2026-06-26 17:43:30 -05:00
- `raw_response` - Exposes the raw [`httpx.Response` ](https://www.python-httpx.org/api/#response ) object if you'd like to handle it directly.
2022-05-03 10:50:34 -05:00
2026-06-26 17:43:30 -05:00
The goal with this `ApiResponse` object is to provide the flexibility to do with the response what you'd like while already having the JSON response deserialized to Python objects.
2022-05-03 10:50:34 -05:00
2026-06-26 17:43:30 -05:00
### Error Handling
You can check `is_successful` or call `raise_for_status()` to raise an exception on failure:
```python
from onspring_api_sdk import OnspringError , OnspringAuthenticationError
response = client . get_apps ()
if not response . is_successful :
print ( f 'Request failed: { response . message } ' )
# Or raise on failure:
try :
response . raise_for_status ()
except OnspringAuthenticationError :
print ( 'Check your API key' )
except OnspringError as e :
print ( f 'Request failed: { e } ' )
```
2022-05-03 10:50:34 -05:00
2022-05-02 15:34:55 -05:00
## Full API Documentation
2026-06-26 17:43:30 -05:00
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 client methods. There is also a [swagger page ](https://api.onspring.com/swagger/index.html ) that you can use for making exploratory requests.
2022-05-02 15:34:55 -05:00
## Example Code
The examples that follow assume you have created an `OnspringClient` as described in the **Start Coding** section.
2022-05-02 16:15:28 -05:00
2022-05-03 11:30:23 -05:00
### Connectivity
#### Verify connectivity
2022-05-02 16:15:28 -05:00
2022-05-02 16:29:34 -05:00
```python
2026-06-26 17:43:30 -05:00
if client . can_connect ():
2022-05-02 16:15:28 -05:00
print ( 'Connected successfully' )
else :
print ( 'Attempt to connect failed' )
```
2022-05-02 16:26:41 -05:00
2022-05-03 11:30:23 -05:00
### Apps
#### Get Apps
2022-05-02 16:26:41 -05:00
2022-05-03 11:04:31 -05:00
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.
2022-05-02 16:29:34 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_apps ()
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
2022-05-02 16:26:41 -05:00
for app in response . data . apps :
print ( f 'Id: { app . id } ' )
print ( f 'Name: { app . name } ' )
print ( f 'href: { app . href } ' )
```
2022-05-03 08:56:47 -05:00
2022-05-03 11:04:31 -05:00
You can set your own page size and page number (max is 1,000) as well.
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import PagingRequest
2022-05-03 14:58:08 -05:00
2026-06-26 17:43:30 -05:00
paging_request = PagingRequest ( page_number = 1 , page_size = 100 )
response = client . get_apps ( paging_request = paging_request )
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
2022-05-03 11:04:31 -05:00
for app in response . data . apps :
print ( f 'Id: { app . id } ' )
print ( f 'Name: { app . name } ' )
print ( f 'href: { app . href } ' )
```
2022-05-03 11:30:23 -05:00
#### Get App By Id
2022-05-03 08:56:47 -05:00
2022-05-03 11:08:19 -05:00
Returns an Onspring app or survey according to provided id.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_app_by_id ( app_id = 195 )
2022-05-03 11:04:31 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 11:08:19 -05:00
print ( f 'id: { response . data . app . id } ' )
print ( f 'Name: { response . data . app . name } ' )
print ( f 'href: { response . data . app . href } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Get Apps By Ids
2022-05-03 08:56:47 -05:00
2022-05-03 11:08:19 -05:00
Returns a collection of Onspring apps and/or surveys according to provided ids.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_apps_by_ids ( app_ids = [ 195 , 240 ])
2022-05-03 11:08:19 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 11:08:19 -05:00
print ( f 'Count: { response . data . count } ' )
for app in response . data . apps :
print ( f 'Id: { app . id } ' )
print ( f 'Name: { app . name } ' )
print ( f 'href: { app . href } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
### Fields
2022-05-03 08:56:47 -05:00
2026-06-26 17:43:30 -05:00
#### Print Field Helper
2022-05-03 08:56:47 -05:00
2026-06-26 17:43:30 -05:00
An example helper for printing field details used in the following examples:
2022-05-03 11:18:35 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import OnspringField
def print_field ( field : OnspringField ):
2022-05-03 11:18:35 -05:00
print ( 'Field:' )
print ( f ' Id: { field . id } ' )
2026-06-26 17:43:30 -05:00
print ( f ' App Id: { field . app_id } ' )
2022-05-03 11:18:35 -05:00
print ( f ' Name: { field . name } ' )
print ( f ' Type: { field . type } ' )
print ( f ' Status: { field . status } ' )
2026-06-26 17:43:30 -05:00
print ( f ' Is Required: { field . is_required } ' )
print ( f ' Is Unique: { field . is_unique } ' )
2022-05-03 11:18:35 -05:00
if field . type == 'Formula' :
2026-06-26 17:43:30 -05:00
print ( f ' Output Type: { field . output_type } ' )
2022-05-03 11:18:35 -05:00
2026-06-26 17:43:30 -05:00
if field . type == 'List' :
print ( f ' Multiplicity: { field . multiplicity } ' )
2022-05-03 11:18:35 -05:00
2026-06-26 17:43:30 -05:00
if field . values :
2022-05-03 11:18:35 -05:00
print ( ' Values:' )
for value in field . values :
2026-06-26 17:43:30 -05:00
print ( f ' { value } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Get Field By Id
2022-05-03 11:33:59 -05:00
Returns an Onspring field according to provided id.
2022-05-03 11:30:23 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_field_by_id ( field_id = 9686 )
2022-05-03 11:30:23 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print_field ( response . data . field )
2022-05-03 11:30:23 -05:00
```
#### Get Fields By Ids
2022-05-03 08:56:47 -05:00
2022-05-03 11:54:23 -05:00
Returns a collection of Onspring fields according to provided ids.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_fields_by_ids ( field_ids = [ 9686 , 9687 ])
2022-05-03 11:40:10 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 11:40:10 -05:00
print ( f 'Count: { response . data . count } ' )
for field in response . data . fields :
2026-06-26 17:43:30 -05:00
print_field ( field )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Get Fields By App Id
2022-05-03 08:56:47 -05:00
2022-05-03 11:54:23 -05:00
Returns a paged collection of fields that can be paged through. By default the page size is 50 and page number is 1.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_fields_by_app_id ( app_id = 195 )
2022-05-03 11:54:23 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
for field in response . data . fields :
print_field ( field )
2022-05-03 11:54:23 -05:00
```
You can set your own page size and page number (max is 1,000) as well.
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import PagingRequest
2022-05-03 14:58:08 -05:00
2026-06-26 17:43:30 -05:00
paging_request = PagingRequest ( page_number = 1 , page_size = 100 )
response = client . get_fields_by_app_id ( app_id = 195 , paging_request = paging_request )
2022-05-03 11:54:23 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
2022-05-03 11:54:23 -05:00
2026-06-26 17:43:30 -05:00
for field in response . data . fields :
print_field ( field )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
### Files
#### Get File Info By Id
2022-05-03 08:56:47 -05:00
2022-05-03 13:06:12 -05:00
Returns the Onspring file's metadata.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_file_info_by_id ( record_id = 1 , field_id = 6990 , file_id = 274 )
2022-05-03 08:56:47 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Name: { response . data . file_info . name } ' )
print ( f 'Type: { response . data . file_info . type } ' )
print ( f 'Owner: { response . data . file_info . owner } ' )
print ( f 'Content Type: { response . data . file_info . content_type } ' )
print ( f 'Created Date: { response . data . file_info . created_date } ' )
print ( f 'Modified Date: { response . data . file_info . modified_date } ' )
print ( f 'File Href: { response . data . file_info . file_href } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Get File By Id
2022-05-03 08:56:47 -05:00
2022-05-03 13:06:12 -05:00
Returns the file itself.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_file_by_id ( record_id = 1 , field_id = 6990 , file_id = 274 )
2022-05-03 12:40:57 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 12:40:57 -05:00
print ( f 'Name: { response . data . file . name } ' )
2026-06-26 17:43:30 -05:00
print ( f 'Content Type: { response . data . file . content_type } ' )
print ( f 'Content Length: { response . data . file . content_length } ' )
2022-05-03 12:40:57 -05:00
2026-06-26 17:43:30 -05:00
file_path = f 'C: \\ Users \\ sfree \\ Documents \\ Temp \\ { response . data . file . name } '
2022-05-03 12:40:57 -05:00
2026-06-26 17:43:30 -05:00
with open ( file_path , "wb" ) as f :
f . write ( response . data . file . content )
2022-05-03 12:40:57 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'File Location: { file_path } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Save File
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import SaveFileRequest
from datetime import datetime
2022-05-03 12:54:32 -05:00
import os
import mimetypes
2026-06-26 17:43:30 -05:00
file_path = 'C: \\ Users \\ sfree \\ Documents \\ Temp \\ Test Attachment.txt'
file_name = os . path . basename ( file_path )
content_type = mimetypes . guess_type ( file_path )[ 0 ]
2022-05-03 12:54:32 -05:00
request = SaveFileRequest (
2026-06-26 17:43:30 -05:00
record_id = 60 ,
field_id = 6989 ,
file_name = file_name ,
file_path = file_path ,
content_type = content_type ,
2022-05-03 12:57:57 -05:00
notes = 'Initial revision' ,
2026-06-26 17:43:30 -05:00
modified_date = datetime . now (),
)
2022-05-03 12:54:32 -05:00
2026-06-26 17:43:30 -05:00
response = client . save_file ( request )
2022-05-03 12:54:32 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 12:54:32 -05:00
print ( f 'File Id: { response . data . id } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 12:40:57 -05:00
#### Delete File By Id
```python
2026-06-26 17:43:30 -05:00
response = client . delete_file_by_id ( record_id = 60 , field_id = 6989 , file_id = 231 )
2022-05-03 13:37:23 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 13:37:23 -05:00
print ( f 'Message: { response . message } ' )
2022-05-03 12:40:57 -05:00
```
2022-05-03 11:30:23 -05:00
### Lists
#### Add Or Update List Value
2022-05-03 08:56:47 -05:00
2022-05-03 13:54:31 -05:00
To add a list value don't provide an id value.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import ListItemRequest
2022-05-03 13:54:31 -05:00
request = ListItemRequest (
2026-06-26 17:43:30 -05:00
list_id = 906 ,
name = 'Not Started' ,
numeric_value = 0 ,
color = '#ffffff' ,
)
2022-05-03 13:54:31 -05:00
2026-06-26 17:43:30 -05:00
response = client . add_or_update_list_item ( request )
2022-05-03 13:54:31 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 13:54:31 -05:00
print ( f 'Id: { response . data . id } ' )
```
To update a list value provide an id value.
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import ListItemRequest
import uuid
2022-05-03 13:54:31 -05:00
request = ListItemRequest (
2026-06-26 17:43:30 -05:00
list_id = 906 ,
name = 'Pending' ,
id = uuid . UUID ( '4118d53a-9121-4345-8682-07f23d606daa' ),
numeric_value = 0 ,
color = '#ffffff' ,
)
2022-05-03 13:54:31 -05:00
2026-06-26 17:43:30 -05:00
response = client . add_or_update_list_item ( request )
2022-05-03 13:54:31 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 13:54:31 -05:00
print ( f 'Id: { response . data . id } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Delete List Value
2022-05-03 13:40:07 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . delete_list_item (
list_id = 906 ,
item_id = '36f94d8c-2b9d-465e-9ad1-ede04109efc9' ,
)
2022-05-03 13:54:31 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 13:54:31 -05:00
print ( f 'Message: { response . message } ' )
2022-05-03 13:40:07 -05:00
```
2022-05-03 11:30:23 -05:00
### Records
#### Get Records By App Id
2022-05-03 08:56:47 -05:00
2026-06-26 17:43:30 -05:00
Returns a paged collection of records that can be paged through. By default the page size is 50 and page number is 1.
2022-05-03 14:58:08 -05:00
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import GetRecordsByAppRequest
2022-05-03 14:58:08 -05:00
2026-06-26 17:43:30 -05:00
request = GetRecordsByAppRequest ( app_id = 195 )
response = client . get_records_by_app_id ( request )
2022-05-03 14:58:08 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
2022-05-03 14:58:08 -05:00
for record in response . data . records :
2026-06-26 17:43:30 -05:00
print ( f 'AppId: { record . app_id } ' )
print ( f 'RecordId: { record . record_id } ' )
2022-05-03 14:58:08 -05:00
for field in record . fields :
print ( f 'Type: { field . type } ' )
2026-06-26 17:43:30 -05:00
print ( f 'FieldId: { field . field_id } ' )
print ( f 'Value: { field . value } ' )
2022-05-03 14:58:08 -05:00
```
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.
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import GetRecordsByAppRequest
from onspring_api_sdk.enums import DataFormat
2022-05-03 14:58:08 -05:00
request = GetRecordsByAppRequest (
2026-06-26 17:43:30 -05:00
app_id = 195 ,
field_ids = [ 9686 ],
data_format = DataFormat . Formatted . name ,
page_number = 1 ,
page_size = 10 ,
)
2022-05-03 14:58:08 -05:00
2026-06-26 17:43:30 -05:00
response = client . get_records_by_app_id ( request )
2022-05-03 14:58:08 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
2022-05-03 14:58:08 -05:00
for record in response . data . records :
2026-06-26 17:43:30 -05:00
print ( f 'AppId: { record . app_id } ' )
print ( f 'RecordId: { record . record_id } ' )
2022-05-03 14:58:08 -05:00
for field in record . fields :
print ( f 'Type: { field . type } ' )
2026-06-26 17:43:30 -05:00
print ( f 'FieldId: { field . field_id } ' )
print ( f 'Value: { field . value } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Get Record By Id
2022-05-03 08:56:47 -05:00
2026-06-26 17:43:30 -05:00
Returns an Onspring record based on the provided app and record ids.
2022-05-03 14:58:08 -05:00
2022-05-03 15:07:38 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import GetRecordByIdRequest
2022-05-03 15:07:38 -05:00
2026-06-26 17:43:30 -05:00
request = GetRecordByIdRequest ( app_id = 195 , record_id = 60 )
response = client . get_record_by_id ( request )
2022-05-03 15:07:38 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'AppId: { response . data . app_id } ' )
print ( f 'RecordId: { response . data . record_id } ' )
2022-05-03 15:07:38 -05:00
for field in response . data . fields :
print ( f 'Type: { field . type } ' )
2026-06-26 17:43:30 -05:00
print ( f 'FieldId: { field . field_id } ' )
print ( f 'Value: { field . value } ' )
2022-05-03 15:07:38 -05:00
```
2022-05-03 15:08:22 -05:00
You can also specify what field values to return and in what format (Raw vs. Formatted) to return them.
2022-05-03 15:07:38 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import GetRecordByIdRequest
from onspring_api_sdk.enums import DataFormat
2022-05-03 15:07:38 -05:00
request = GetRecordByIdRequest (
2026-06-26 17:43:30 -05:00
app_id = 195 ,
record_id = 60 ,
field_ids = [ 9686 ],
data_format = DataFormat . Formatted . name ,
)
2022-05-03 15:07:38 -05:00
2026-06-26 17:43:30 -05:00
response = client . get_record_by_id ( request )
2022-05-03 15:07:38 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'AppId: { response . data . app_id } ' )
print ( f 'RecordId: { response . data . record_id } ' )
2022-05-03 15:07:38 -05:00
for field in response . data . fields :
print ( f 'Type: { field . type } ' )
2026-06-26 17:43:30 -05:00
print ( f 'FieldId: { field . field_id } ' )
print ( f 'Value: { field . value } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Delete Record By Id
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . delete_record_by_id ( app_id = 195 , record_id = 60 )
2022-05-03 15:09:55 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 15:09:55 -05:00
print ( f 'Message: { response . message } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Get Records By Ids
2022-05-03 08:56:47 -05:00
2022-05-03 15:14:11 -05:00
Returns a collection of Onspring records based on the provided appId and recordIds.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import GetBatchRecordsRequest
2022-05-03 15:14:11 -05:00
2026-06-26 17:43:30 -05:00
request = GetBatchRecordsRequest ( app_id = 195 , record_ids = [ 1 , 2 , 3 ])
response = client . get_records_by_ids ( request )
2022-05-03 15:14:11 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 15:14:11 -05:00
print ( f 'Count: { response . data . count } ' )
for record in response . data . records :
2026-06-26 17:43:30 -05:00
print ( f 'AppId: { record . app_id } ' )
print ( f 'RecordId: { record . record_id } ' )
2022-05-03 15:14:11 -05:00
for field in record . fields :
print ( f 'Type: { field . type } ' )
2026-06-26 17:43:30 -05:00
print ( f 'FieldId: { field . field_id } ' )
print ( f 'Value: { field . value } ' )
2022-05-03 15:14:11 -05:00
```
You can also specify what field values to return and in what format (Raw vs. Formatted) to return them.
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import GetBatchRecordsRequest
from onspring_api_sdk.enums import DataFormat
2022-05-03 15:14:11 -05:00
request = GetBatchRecordsRequest (
2026-06-26 17:43:30 -05:00
app_id = 195 ,
record_ids = [ 1 , 2 , 3 ],
field_ids = [ 9686 ],
data_format = DataFormat . Formatted . name ,
)
2022-05-03 15:14:11 -05:00
2026-06-26 17:43:30 -05:00
response = client . get_records_by_ids ( request )
2022-05-03 15:14:11 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 15:14:11 -05:00
print ( f 'Count: { response . data . count } ' )
for record in response . data . records :
2026-06-26 17:43:30 -05:00
print ( f 'AppId: { record . app_id } ' )
print ( f 'RecordId: { record . record_id } ' )
2022-05-03 15:14:11 -05:00
for field in record . fields :
print ( f 'Type: { field . type } ' )
2026-06-26 17:43:30 -05:00
print ( f 'FieldId: { field . field_id } ' )
print ( f 'Value: { field . value } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Query Records
2022-05-03 08:56:47 -05:00
2026-06-26 17:43:30 -05:00
Returns a paged collection of records based on a criteria that can be paged through. By default the page size is 50 and page number is 1.
2022-05-03 15:30:00 -05:00
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import QueryRecordsRequest
2022-05-03 15:30:00 -05:00
2026-06-26 17:43:30 -05:00
field_id = 6983
2022-05-03 15:30:00 -05:00
operator = 'eq'
2026-06-26 17:43:30 -05:00
value = "'Test Task 5'"
2022-05-03 15:30:00 -05:00
2026-06-26 17:43:30 -05:00
request = QueryRecordsRequest ( app_id = 195 , filter = f ' { field_id } { operator } { value } ' )
response = client . query_records ( request )
2022-05-03 15:30:00 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
2022-05-03 15:30:00 -05:00
for record in response . data . records :
2026-06-26 17:43:30 -05:00
print ( f 'AppId: { record . app_id } ' )
print ( f 'RecordId: { record . record_id } ' )
2022-05-03 15:30:00 -05:00
for field in record . fields :
print ( f 'Type: { field . type } ' )
2026-06-26 17:43:30 -05:00
print ( f 'FieldId: { field . field_id } ' )
print ( f 'Value: { field . value } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 15:30:00 -05:00
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.
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import QueryRecordsRequest
from onspring_api_sdk.enums import DataFormat
2022-05-03 15:30:00 -05:00
2026-06-26 17:43:30 -05:00
field_id = 6983
2022-05-03 15:30:00 -05:00
operator = 'eq'
2026-06-26 17:43:30 -05:00
value = "'Test Task 5'"
2022-05-03 15:30:00 -05:00
request = QueryRecordsRequest (
2026-06-26 17:43:30 -05:00
app_id = 195 ,
filter = f ' { field_id } { operator } { value } ' ,
field_ids = [ 9686 ],
data_format = DataFormat . Formatted . name ,
page_number = 1 ,
page_size = 10 ,
)
2022-05-03 15:30:00 -05:00
2026-06-26 17:43:30 -05:00
response = client . query_records ( request )
2022-05-03 15:30:00 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
2022-05-03 15:30:00 -05:00
for record in response . data . records :
2026-06-26 17:43:30 -05:00
print ( f 'AppId: { record . app_id } ' )
print ( f 'RecordId: { record . record_id } ' )
2022-05-03 15:30:00 -05:00
for field in record . fields :
print ( f 'Type: { field . type } ' )
2026-06-26 17:43:30 -05:00
print ( f 'FieldId: { field . field_id } ' )
print ( f 'Value: { field . value } ' )
2022-05-03 15:30:00 -05:00
```
2022-05-03 15:36:17 -05:00
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.
2022-05-03 15:30:00 -05:00
2022-05-03 11:30:23 -05:00
#### Add or Update A Record
2022-05-03 08:56:47 -05:00
2022-05-03 16:50:18 -05:00
You can add a record by not providing a record id value. If successful will return the id of the added record.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import (
StringFieldValue ,
GuidFieldValue ,
DateFieldValue ,
IntegerListValue ,
Record ,
)
import uuid
from datetime import datetime
2022-05-03 16:50:18 -05:00
fields = []
status = uuid . UUID ( '4118d53a-9121-4345-8682-07f23d606daa' )
2026-06-26 17:43:30 -05:00
due_date = datetime . utcnow ()
2022-05-03 16:50:18 -05:00
2026-06-26 17:43:30 -05:00
fields . append ( StringFieldValue ( field_id = 6983 , value = 'Test Task via API' ))
fields . append ( StringFieldValue ( field_id = 6984 , value = 'This is a task.' ))
fields . append ( GuidFieldValue ( field_id = 6986 , value = status ))
fields . append ( DateFieldValue ( field_id = 6985 , value = due_date ))
fields . append ( IntegerListValue ( field_id = 6987 , value = [ 4 ]))
2022-05-03 16:50:18 -05:00
2026-06-26 17:43:30 -05:00
record = Record ( app_id = 195 , fields = fields )
2022-05-03 16:50:18 -05:00
2026-06-26 17:43:30 -05:00
response = client . add_or_update_record ( record )
2022-05-03 16:50:18 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 16:50:18 -05:00
print ( f 'Id: { response . data . id } ' )
2026-06-26 17:43:30 -05:00
2022-05-03 16:50:18 -05:00
for warning in response . data . warnings :
print ( f 'Warning: { warning } ' )
```
2022-05-03 16:51:02 -05:00
You can update a record by providing its id. If successful will return the id of record updated.
2022-05-03 16:50:18 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import (
StringFieldValue ,
GuidFieldValue ,
DateFieldValue ,
IntegerListValue ,
Record ,
)
import uuid
from datetime import datetime
2022-05-04 10:32:43 -05:00
2022-05-03 16:50:18 -05:00
fields = []
status = uuid . UUID ( '1c1c5f7e-cd03-4b70-9790-0f83b24b5863' )
2026-06-26 17:43:30 -05:00
due_date = datetime . utcnow ()
2022-05-03 16:50:18 -05:00
2026-06-26 17:43:30 -05:00
fields . append ( StringFieldValue ( field_id = 6983 , value = 'Test Task via API' ))
fields . append ( StringFieldValue ( field_id = 6984 , value = 'This is a task.' ))
fields . append ( GuidFieldValue ( field_id = 6986 , value = status ))
fields . append ( DateFieldValue ( field_id = 6985 , value = due_date ))
fields . append ( IntegerListValue ( field_id = 6987 , value = [ 4 ]))
2022-05-03 16:50:18 -05:00
2026-06-26 17:43:30 -05:00
record = Record ( app_id = 195 , fields = fields , record_id = 103 )
2022-05-03 16:50:18 -05:00
2026-06-26 17:43:30 -05:00
response = client . add_or_update_record ( record )
2022-05-03 16:50:18 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-03 16:50:18 -05:00
print ( f 'Id: { response . data . id } ' )
2026-06-26 17:43:30 -05:00
2022-05-03 16:50:18 -05:00
for warning in response . data . warnings :
print ( f 'Warning: { warning } ' )
2022-05-03 08:56:47 -05:00
```
2022-05-03 11:30:23 -05:00
#### Delete Records By Ids
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import DeleteBatchRecordsRequest
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
request = DeleteBatchRecordsRequest ( app_id = 195 , record_ids = [ 1 , 2 , 3 ])
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
response = client . delete_records_by_ids ( request )
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-04 09:07:21 -05:00
print ( f 'Message: { response . message } ' )
2022-05-03 11:30:23 -05:00
```
### Reports
#### Get Report By Id
2022-05-04 09:07:21 -05:00
Returns the report for the provided id.
2022-05-03 11:30:23 -05:00
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import GetReportByIdRequest
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
request = GetReportByIdRequest ( report_id = 53 )
response = client . get_report_by_id ( request )
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-04 09:07:21 -05:00
print ( 'Columns:' )
print ( f ' { ", " . join ( response . data . columns ) } ' )
print ( 'Rows:' )
2026-06-26 17:43:30 -05:00
2022-05-04 09:07:21 -05:00
for row in response . data . rows :
2026-06-26 17:43:30 -05:00
cells = ', ' . join ([ str ( cell ) for cell in row . cells ])
print ( f 'Record Id { row . record_id } : { cells } ' )
2022-05-04 09:07:21 -05:00
```
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.
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import GetReportByIdRequest
from onspring_api_sdk.enums import DataFormat , ReportDataType
2022-05-04 09:07:21 -05:00
request = GetReportByIdRequest (
2026-06-26 17:43:30 -05:00
report_id = 53 ,
api_data_format = DataFormat . Formatted . name ,
data_type = ReportDataType . ChartData . name ,
)
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
response = client . get_report_by_id ( request )
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-04 09:07:21 -05:00
print ( 'Columns:' )
print ( f ' { ", " . join ( response . data . columns ) } ' )
print ( 'Rows:' )
2026-06-26 17:43:30 -05:00
2022-05-04 09:07:21 -05:00
for row in response . data . rows :
2026-06-26 17:43:30 -05:00
cells = ', ' . join ([ str ( cell ) for cell in row . cells ])
print ( f 'Record Id { row . record_id } : { cells } ' )
2022-05-03 11:30:23 -05:00
```
#### Get Reports By App Id
2022-05-03 08:56:47 -05:00
2022-05-04 09:07:21 -05:00
Returns a paged collection of reports that can be paged through. By default the page size is 50 and page number is 1.
2022-05-03 08:56:47 -05:00
```python
2026-06-26 17:43:30 -05:00
response = client . get_reports_by_app_id ( app_id = 195 )
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
2022-05-04 09:07:21 -05:00
print ( 'Reports:' )
for report in response . data . reports :
print ( f ' Id: { report . id } ' )
print ( f ' Name: { report . name } ' )
print ( f ' Description: { report . description } ' )
```
You can set your own page size and page number (max is 1,000) as well.
```python
2026-06-26 17:43:30 -05:00
from onspring_api_sdk.models import PagingRequest
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
paging_request = PagingRequest ( page_number = 1 , page_size = 10 )
response = client . get_reports_by_app_id ( app_id = 195 , paging_request = paging_request )
2022-05-04 09:07:21 -05:00
2026-06-26 17:43:30 -05:00
print ( f 'Status Code: { response . status_code } ' )
print ( f 'Page Number: { response . data . page_number } ' )
print ( f 'Page Size: { response . data . page_size } ' )
print ( f 'Total Pages: { response . data . total_pages } ' )
print ( f 'Total Records: { response . data . total_records } ' )
2022-05-04 09:07:21 -05:00
print ( 'Reports:' )
for report in response . data . reports :
print ( f ' Id: { report . id } ' )
print ( f ' Name: { report . name } ' )
print ( f ' Description: { report . description } ' )
2022-05-03 08:56:47 -05:00
```