From 9a0578b201ae89b5648efee9e1770dcf72039dfd Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Thu, 13 Apr 2023 23:38:07 -0500 Subject: [PATCH] docs: add get record by id section --- src/app/components/Section.module.css | 5 ++ src/docs/version_002/docsStructure.ts | 11 +-- .../records/get_record_by_id/copy.md | 47 ++++++++++ .../records/get_record_by_id/example.md | 90 +++++++++++++++++++ .../records/get_records_by_app/copy.md | 42 ++++++++- .../records/get_records_by_app/example.md | 16 ++-- 6 files changed, 200 insertions(+), 11 deletions(-) create mode 100644 src/docs/version_002/resources/records/get_record_by_id/copy.md create mode 100644 src/docs/version_002/resources/records/get_record_by_id/example.md diff --git a/src/app/components/Section.module.css b/src/app/components/Section.module.css index 8b484bb..8b7972d 100644 --- a/src/app/components/Section.module.css +++ b/src/app/components/Section.module.css @@ -39,6 +39,11 @@ border-radius: 5px; } +.container>article>p>code, +.container>article>table code { + padding: 0.1rem 0.5rem; +} + .container>article:nth-child(1)>h1 { color: #ee7203; font-size: 40px; diff --git a/src/docs/version_002/docsStructure.ts b/src/docs/version_002/docsStructure.ts index f7b49a7..ca31d75 100644 --- a/src/docs/version_002/docsStructure.ts +++ b/src/docs/version_002/docsStructure.ts @@ -9,35 +9,30 @@ export const versionTwo: DocsStructure = { folder: 'introduction', copy: 'copy.md', example: 'example.md', - children: [], }, { title: 'Authentication', folder: 'authentication', copy: 'copy.md', example: 'example.md', - children: [], }, { title: 'Data Format', folder: 'data_format', copy: 'copy.md', example: 'example.md', - children: [], }, { title: 'Pagination', folder: 'pagination', copy: 'copy.md', example: 'example.md', - children: [], }, { title: 'Error Handling', folder: 'error_handling', copy: 'copy.md', example: 'example.md', - children: [], }, { title: 'Resources', @@ -61,6 +56,12 @@ export const versionTwo: DocsStructure = { copy: 'copy.md', example: 'example.md', }, + { + title: 'Get Record by Id', + folder: 'get_record_by_id', + copy: 'copy.md', + example: 'example.md', + }, ], }, ], diff --git a/src/docs/version_002/resources/records/get_record_by_id/copy.md b/src/docs/version_002/resources/records/get_record_by_id/copy.md new file mode 100644 index 0000000..e295b64 --- /dev/null +++ b/src/docs/version_002/resources/records/get_record_by_id/copy.md @@ -0,0 +1,47 @@ +# Get Record by Id {% #get-record-by-id %} + +This endpoint returns a single [record](#records) based on the given record id. + +## Path Parameters + +{% table %} + +- Parameter Name +- Data Type +- Description + +--- + +- appId +- `number` +- The id of the app or survey that the record belongs to. + +--- + +- recordId +- `number` +- The id of the record. + +{% /table %} + +## Query Parameters + +{% table %} + +- Parameter Name +- Data Type +- Description + +--- + +- fieldIds +- `string` +- A comma-separated list of field ids to include in the response. If not specified, all fields will be returned. + +--- + +- 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 %} 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 new file mode 100644 index 0000000..868fa48 --- /dev/null +++ b/src/docs/version_002/resources/records/get_record_by_id/example.md @@ -0,0 +1,90 @@ +# Retrieving a record from an app + +{% code heading="GET /Records/appId/{appID}/recordId/{recordID}" defaultLanguage="bash" %} + +```bash +curl --location 'https://api.onspring.com/Records/appId/195/recordId/1' \ +--header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' +``` + +```csharp +using Onspring.API.SDK; + +var onspringClient = new OnspringClient( + config.BaseUrl, + config.ApiKey +); + +var getRequest = new GetRecordRequest +{ + AppId = 195, + RecordId = 1, +}; + +var getResponse = await onspringClient.GetRecordAsync(getRequest); +var record = getResponse.Value; + +foreach (var recordFieldValue in record.FieldData) +{ + Console.WriteLine($"FieldId: {recordFieldValue.FieldId}, Type: {recordFieldValue.Type}, Value: {recordFieldValue.Value}"); +} +``` + +```javascript +import { + GetRecordRequest, + 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 GetRecordRequest(195, 1); +const res = await client.getRecordById(request); +const record = res.data; + +console.log(record); +``` + +```python +from OnspringApiSdk.OnspringClient import OnspringClient +from OnspringApiSdk.Models import GetRecordByIdRequest +from configparser import ConfigParser + +request = GetRecordByIdRequest(appId=195, recordId=1) + +response = client.GetRecordById(request) + +print(f'Status Code: {response.statusCode}') +print(f'AppId: {response.data.appId}') +print(f'RecordId: {response.data.recordId}') + +for field in response.data.fields: + print(f'Type: {field.type}') + print(f'FieldId: {field.fieldId}') + print(f'Value: {field.GetResultValueString()}') +``` + +{% /code %} + +{% code heading="RESPONSE" defaultLanguage="json" %} + +```json +{ + "appId": 195, + "recordId": 1, + "fieldData": [ + { + "type": "Integer", + "fieldId": 6976, + "value": 1 + } + ] +} +``` + +{% /code %} diff --git a/src/docs/version_002/resources/records/get_records_by_app/copy.md b/src/docs/version_002/resources/records/get_records_by_app/copy.md index ce4e233..5d87d56 100644 --- a/src/docs/version_002/resources/records/get_records_by_app/copy.md +++ b/src/docs/version_002/resources/records/get_records_by_app/copy.md @@ -1,3 +1,43 @@ # Get Records by App {% #get-records-by-app %} -Some place holder text. +This endpoint returns a [paged](#pagination) collection of [records](#records) for a given app or survey. + +## Path Parameters + +{% table %} + +- Parameter Name +- Data Type +- Description + +--- + +- appId +- `number` +- The id of the app or survey. + +{% /table %} + +## Query Parameters + +**Note:** [Pagination](#pagination) query parameters can be used to control the number of records returned. + +{% table %} + +- Parameter Name +- Data Type +- Description + +--- + +- fieldIds +- `string` +- A comma-separated list of field ids to include in the response. If not specified, all fields will be returned. + +--- + +- 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 %} 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 d99681b..3899d85 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 @@ -42,6 +42,7 @@ for (const app of apps) { ```python from OnspringApiSdk.OnspringClient import OnspringClient +from OnspringApiSdk.Models import GetRecordsByAppRequest from configparser import ConfigParser cfg = ConfigParser() @@ -51,7 +52,8 @@ key = cfg['prod']['key'] url = cfg['prod']['url'] client = OnspringClient(url, key) -response = client.GetApps() +request = GetRecordsByAppRequest(appId=195) +response = client.GetRecordsByAppId(request) print(f'Status Code: {response.statusCode}') print(f'Page Size: {response.data.pageSize}') @@ -59,10 +61,14 @@ print(f'Page Number: {response.data.pageNumber}') print(f'Total Pages: {response.data.totalPages}') print(f'Total Records: {response.data.totalRecords}') -for app in response.data.apps: - print(f'Id: {app.id}') - print(f'Name: {app.name}') - print(f'href: {app.href}') +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 %}