From c3f65626bee4c34432544ebde87ffceceaf00f70 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Fri, 14 Apr 2023 21:28:36 -0500 Subject: [PATCH] docs: add get records by ids section --- src/docs/version_002/docsStructure.ts | 6 + .../records/get_record_by_id/example.md | 1 + .../records/get_records_by_app/example.md | 7 +- .../records/get_records_by_ids/copy.md | 59 +++++++ .../records/get_records_by_ids/example.md | 147 ++++++++++++++++++ 5 files changed, 217 insertions(+), 3 deletions(-) create mode 100644 src/docs/version_002/resources/records/get_records_by_ids/copy.md create mode 100644 src/docs/version_002/resources/records/get_records_by_ids/example.md diff --git a/src/docs/version_002/docsStructure.ts b/src/docs/version_002/docsStructure.ts index ca31d75..47640ba 100644 --- a/src/docs/version_002/docsStructure.ts +++ b/src/docs/version_002/docsStructure.ts @@ -62,6 +62,12 @@ export const versionTwo: DocsStructure = { copy: 'copy.md', example: 'example.md', }, + { + title: 'Get Records by Ids', + folder: 'get_records_by_ids', + copy: 'copy.md', + example: 'example.md', + }, ], }, ], diff --git a/src/docs/version_002/resources/records/get_record_by_id/example.md b/src/docs/version_002/resources/records/get_record_by_id/example.md index 868fa48..c3fef32 100644 --- a/src/docs/version_002/resources/records/get_record_by_id/example.md +++ b/src/docs/version_002/resources/records/get_record_by_id/example.md @@ -9,6 +9,7 @@ curl --location 'https://api.onspring.com/Records/appId/195/recordId/1' \ ```csharp using Onspring.API.SDK; +using Onspring.API.SDK.Models; var onspringClient = new OnspringClient( config.BaseUrl, diff --git a/src/docs/version_002/resources/records/get_records_by_app/example.md b/src/docs/version_002/resources/records/get_records_by_app/example.md index 3899d85..961ac92 100644 --- a/src/docs/version_002/resources/records/get_records_by_app/example.md +++ b/src/docs/version_002/resources/records/get_records_by_app/example.md @@ -15,10 +15,11 @@ var onspringClient = new OnspringClient( config.ApiKey ); -var apps = await onspringClient.GetAppsAsync(); -foreach (App app in apps) +var response = await onspringClient.GetAppsAsync(); + +foreach (var app in response.Value.Items) { - Console.WriteLine($"{app.Id}, {app.Name}"); + Console.WriteLine($"{app.Id}, {app.Name}"); } ``` diff --git a/src/docs/version_002/resources/records/get_records_by_ids/copy.md b/src/docs/version_002/resources/records/get_records_by_ids/copy.md new file mode 100644 index 0000000..59b789a --- /dev/null +++ b/src/docs/version_002/resources/records/get_records_by_ids/copy.md @@ -0,0 +1,59 @@ +# Get Records by Ids {% #get-records-by-ids %} + +This endpoint returns a batch of [records](#records) that match the given ids. + +## Request Body Properties + +{% table %} + +- Property Name +- Data Type +- Description + +--- + +- appId +- `number` +- The id of the app that contains the records. + +--- + +- recordIds +- `number[]` +- The ids of the records to return. + +--- + +- fieldIds +- `number[]` +- The ids of the fields to return in the records. + +--- + +- dataFormat +- `string` +- The [format](#data-format) of the field data in the response. Valid values are `raw` and `formatted`. If not specified, `raw` will be used. + +{% /table %} + +## Response Body Properties + +{% table %} + +- Property Name +- Data Type +- Description + +--- + +- count +- `number` +- The number of records returned. + +--- + +- items +- `object[]` +- The [records](#records) returned. + +{% /table %} diff --git a/src/docs/version_002/resources/records/get_records_by_ids/example.md b/src/docs/version_002/resources/records/get_records_by_ids/example.md new file mode 100644 index 0000000..4b92ac0 --- /dev/null +++ b/src/docs/version_002/resources/records/get_records_by_ids/example.md @@ -0,0 +1,147 @@ +# Retrieving a batch of records + +{% code heading="POST /Records/batch-get" defaultLanguage="bash" %} + +```bash +curl --location 'https://api.onspring.com/Records/batch-get' \ +--header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' \ +--header 'x-api-version: 2' \ +--header 'Content-Type: application/json' \ +--data '{ + "AppId": 195, + "RecordIds": [1], + "FieldIds": [6983,6986,6987,6985,6984], + "DataFormat": "Raw" +}' +``` + +```csharp +using Onspring.API.SDK; +using Onspring.API.SDK.Models; +using Onspring.API.SDK.Enums; + +var onspringClient = new OnspringClient( + config.BaseUrl, + config.ApiKey +); + +var request = new GetRecordsRequest +{ + AppId = 195, + RecordIds = new List { 1, }, + FieldIds = new List { 6983, 6986, 6987, 6985, 6984 }, + DataFormat = DataFormat.Raw, +}; +var response = await onspringClient.GetRecordsAsync(request); + +foreach (var record in response.Value.Items) +{ + Console.WriteLine($"{record.AppId}, {record.RecordId}"); +} +``` + +```javascript +import { + DataFormat, + GetRecordsRequest, + OnspringClient, +} from 'onspring-api-sdk'; +import dotenv from 'dotenv'; +dotenv.config(); + +const client = new OnspringClient( + process.env.BASE_URL, + process.env.API_KEY +); + +const request = new GetRecordsRequest( + 195, + [1], + [6983, 6986, 6987, 6985, 6984], + DataFormat.Raw +); +const res = await client.getRecordsByIds(request); +const records = res.data.items; + +for (const record of records) { + console.log(record); +} +``` + +```python +from OnspringApiSdk.OnspringClient import OnspringClient +from OnspringApiSdk.Models import GetBatchRecordsRequest +from configparser import ConfigParser + +cfg = ConfigParser() +cfg.read('config.ini') + +key = cfg['prod']['key'] +url = cfg['prod']['url'] + +client = OnspringClient(url, key) +request = GetBatchRecordsRequest( + appId=195, + recordIds=[1], + fieldIds=[6983, 6986, 6987, 6985, 6984], + dataFormat='Raw' +) +response = client.GetRecordsByIds(request) + +print(f'Status Code: {response.statusCode}') +print(f'Count: {response.data.count}') + +for record in response.data.records: + print(f'AppId: {record.appId}') + print(f'RecordId: {record.recordId}') + + for field in record.fields: + print(f'Type: {field.type}') + print(f'FieldId: {field.fieldId}') + print(f'Value: {field.GetResultValueString()}') +``` + +{% /code %} + +{% code heading="RESPONSE" defaultLanguage="json" %} + +```json +{ + "count": 1, + "items": [ + { + "appId": 195, + "recordId": 1, + "fieldData": [ + { + "type": "String", + "fieldId": 6983, + "value": "Test Task 1" + }, + { + "type": "Guid", + "fieldId": 6986, + "value": "4118d53a-9121-4345-8682-07f23d606daa" + }, + { + "type": "Integer", + "fieldId": 6987, + "value": 2 + }, + { + "type": "Date", + "fieldId": 6985, + "value": "2021-12-31T06:00:00Z" + }, + { + "type": "String", + "fieldId": 6984, + "value": "

This is a test!

" + } + ] + } + ] +} +``` + +{% /code %}