From aeed070d89c4fd3daf0dc0c984e22e5c334c538c Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Sat, 15 Apr 2023 21:48:13 -0500 Subject: [PATCH] docs: add delete record by id section --- .vscode/settings.json | 3 +- .../records/delete_record_by_id/copy.md | 24 ++++ .../records/delete_record_by_id/example.md | 61 ++++++++ .../records/get_records_by_ids/example.md | 9 +- .../records/get_records_by_query/example.md | 9 +- .../resources/records/save_record/copy.md | 52 +++++++ .../resources/records/save_record/example.md | 136 ++++++++++++++++++ 7 files changed, 283 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f377809..b1b1d0e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "markdoc", "notnull", "Onpsring", - "prismjs" + "prismjs", + "utcnow" ] } diff --git a/src/docs/version_002/resources/records/delete_record_by_id/copy.md b/src/docs/version_002/resources/records/delete_record_by_id/copy.md index 8e78d2c..3da6360 100644 --- a/src/docs/version_002/resources/records/delete_record_by_id/copy.md +++ b/src/docs/version_002/resources/records/delete_record_by_id/copy.md @@ -1 +1,25 @@ # Delete Record by Id {% #delete-record-by-id %} + +This endpoint allows you to delete a record from an app. When successful, a `204` response will be returned with no body. + +## Path Parameters + +{% table %} + +- Parameter Name +- Data Type +- Description + +--- + +- appId +- `number` +- The id of the app that contains the record. + +--- + +- recordId +- `number` +- The id of the record to delete. + +{% /table %} diff --git a/src/docs/version_002/resources/records/delete_record_by_id/example.md b/src/docs/version_002/resources/records/delete_record_by_id/example.md index 7030332..ba25932 100644 --- a/src/docs/version_002/resources/records/delete_record_by_id/example.md +++ b/src/docs/version_002/resources/records/delete_record_by_id/example.md @@ -1 +1,62 @@ # Deleting a record from an app + +{% code method="DELETE" heading="/Records/appId/{appId}/recordId/{recordId}" defaultLanguage="bash" %} + +```bash +curl --location --request DELETE 'https://api.onspring.com/Records/appId/195/recordId/140' \ +--header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' \ +--data '' +``` + +```csharp +using Onspring.API.SDK; +using System.Net; + +var onspringClient = new OnspringClient( + config.BaseUrl, + config.ApiKey +); + +var appId =195; +var recordId = 140; +var deleteResponse = await onspringClient.DeleteRecordAsync(appId, recordId); + +if (deleteResponse.StatusCode == HttpStatusCode.NoContent) +{ + Console.WriteLine("Record deleted"); +} +``` + +```javascript +import { OnspringClient } from 'onspring-api-sdk'; + +const client = new OnspringClient( + process.env.BASE_URL, + process.env.API_KEY +); + +const res = await client.deleteRecordById(195, 140); + +res.statusCode === 204 + ? console.log('Record deleted') + : console.log('Error deleting record'); +``` + +```python +from OnspringApiSdk.OnspringClient import OnspringClient +from configparser import ConfigParser + +cfg = ConfigParser() +cfg.read('config.ini') + +key = cfg['prod']['key'] +url = cfg['prod']['url'] + +client = OnspringClient(url, key) +response = client.DeleteRecordById(appId=195, recordId=140) + +print(f'Status Code: {response.statusCode}') +print(f'Message: {response.message}') +``` + +{% /code %} 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 index ab9f8f7..882070f 100644 --- 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 @@ -5,13 +5,12 @@ ```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" + "appId": 195, + "recordIds": [1], + "fieldIds": [6983,6986,6987,6985,6984], + "dataFormat": "Raw" }' ``` diff --git a/src/docs/version_002/resources/records/get_records_by_query/example.md b/src/docs/version_002/resources/records/get_records_by_query/example.md index 8ced4e6..2cf88e0 100644 --- a/src/docs/version_002/resources/records/get_records_by_query/example.md +++ b/src/docs/version_002/resources/records/get_records_by_query/example.md @@ -5,13 +5,12 @@ ```bash curl --location 'https://api.onspring.com/Records/Query' \ --header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' \ ---header 'x-api-version: 2' \ --header 'Content-Type: application/json' \ --data '{ - "AppId": 195, - "Filter": "6983 eq '\''Test Task 5'\''", - "FieldIds": [6983,6986,6987,6985,6984], - "DataFormat": "Formatted" + "appId": 195, + "filter": "6983 eq '\''Test Task 5'\''", + "fieldIds": [6983,6986,6987,6985,6984], + "dataFormat": "Formatted" }' ``` diff --git a/src/docs/version_002/resources/records/save_record/copy.md b/src/docs/version_002/resources/records/save_record/copy.md index d4e75f2..3a02c25 100644 --- a/src/docs/version_002/resources/records/save_record/copy.md +++ b/src/docs/version_002/resources/records/save_record/copy.md @@ -1 +1,53 @@ # Save Record {% #save-record %} + +This endpoint allows you to add or update a record in an app. If a record id is provided in the request, the record will be updated and a `200` response will be returned. If no record id is provided, a new record will be created and a `201` response will be returned. When successful the response will contain the record id of the record that was created or updated and any warnings that were encountered. + +## Request Body Properties + +{% table %} + +- Property Name +- Data Type +- Description + +--- + +- appId +- `number` +- The id of the app that contains or will contain the record. + +--- + +- recordId +- `number` +- The id of the record to update. If this property is not provided, a new record will be created. + +--- + +- fields +- `object` +- An object containing the field values to save. The keys of the object should be the field ids and the values should be the field values. The field values should be in the format that is expected by the field type. + +{% /table %} + +## Response Body Properties + +{% table %} + +- Property Name +- Data Type +- Description + +--- + +- recordId +- `number` +- The id of the record that was created or updated. + +--- + +- warnings +- `string[]` +- An array of warnings that were encountered while saving the record. + +{% /table %} diff --git a/src/docs/version_002/resources/records/save_record/example.md b/src/docs/version_002/resources/records/save_record/example.md index a817e92..8853f36 100644 --- a/src/docs/version_002/resources/records/save_record/example.md +++ b/src/docs/version_002/resources/records/save_record/example.md @@ -1 +1,137 @@ # Add a record to an app + +{% code method="PUT" heading="/Records" defaultLanguage="bash" %} + +```bash +curl --location --request PUT 'https://api.onspring.com/Records' \ +--header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' \ +--header 'Content-Type: application/json' \ +--data '{ + "appId": 195, + "recordId": null, + "fields": { + 6983: "A New Test Task", + 6984: "This is a test task.", + 6985: "12/25/2021", + 6986: "4118d53a-9121-4345-8682-07f23d606daa", + 6987: [4] + } +}' +``` + +```csharp +using Onspring.API.SDK; +using Onspring.API.SDK.Models; + +var onspringClient = new OnspringClient( + config.BaseUrl, + config.ApiKey +); + +var record = new ResultRecord +{ + AppId = 195, + FieldData = new List + { + new StringFieldValue(6983, "A New Test Task"), + new StringFieldValue(6984, "This is a test task."), + new DateFieldValue(6985, DateTime.Parse("12/25/2021")), + new GuidFieldValue(6986, Guid.Parse("4118d53a-9121-4345-8682-07f23d606daa")), + new IntegerListFieldValue(6987, new List { 4 }), + }, +}; + +var saveResponse = await onspringClient.SaveRecordAsync(record); + +Console.WriteLine($"New Record Id is: {saveResponse.Value.Id}"); + +foreach (string warning in saveResponse.Value.Warnings) +{ + Console.WriteLine($"Warning: {warning}"); +} +``` + +```javascript +import { + DateRecordValue, + GuidRecordValue, + IntegerListRecordValue, + OnspringClient, + Record, + StringRecordValue, +} from 'onspring-api-sdk'; +import dotenv from 'dotenv'; +dotenv.config(); + +const client = new OnspringClient( + process.env.BASE_URL, + process.env.API_KEY +); + +const record = new Record(195, null); +record.addValues([ + new StringRecordValue(6983, 'A New Test Task'), + new StringRecordValue(6984, 'This is a test task.'), + new DateRecordValue(6985, new Date('12/25/2021')), + new GuidRecordValue( + 6986, + '4118d53a-9121-4345-8682-07f23d606daa' + ), + new IntegerListRecordValue(6987, [4]), +]); + +const res = await client.saveRecord(record); +const newRecordId = res.data.id; + +console.log(newRecordId); +``` + +```python +from OnspringApiSdk.OnspringClient import OnspringClient +from OnspringApiSdk.Models import StringFieldValue, GuidFieldValue, DateFieldValue, IntegerListValue, Record +from configparser import ConfigParser + +fields = [] + +fields.append(StringFieldValue(6983, 'A New Test Task')) +fields.append(StringFieldValue(6984, 'This is a test task.')) +fields.append( + GuidFieldValue( + 6986, + uuid.UUID('4118d53a-9121-4345-8682-07f23d606daa') + ) +) +fields.append( + DateFieldValue( + 6985, + datetime.datetime(2021, 12, 25) + ) +) +fields.append(IntegerListValue(6987, [4])) + +record = Record( + appId=195, + fields +) + +response = client.AddOrUpdateRecord(record) + +print(f'Status Code: {response.statusCode}') +print(f'Id: {response.data.id}') + +for warning in response.data.warnings: + print(f'Warning: {warning}') +``` + +{% /code %} + +{% code heading="Response" defaultLanguage="json" %} + +```json +{ + "warnings": [], + "id": 140 +} +``` + +{% /code %}