diff --git a/src/docs/version_002/resources/files/copy.md b/src/docs/version_002/resources/files/copy.md index 76581bf..a7f0720 100644 --- a/src/docs/version_002/resources/files/copy.md +++ b/src/docs/version_002/resources/files/copy.md @@ -1 +1,61 @@ # Files {% #files %} + +Files represent the information held in `Attachment` and `Image` fields. The Onspring API can be used to retrieve the information about files and to the files themselves. The Onspring API can also be used to add and remove files to and from `Attachment` and `Image` fields. + +## File Information Properties {% #file-information-properties %} + +{% table %} + +- Property Name +- Data Type +- Description + +--- + +- type +- `string` +- The type of the file. This will be either `Attachment` or `Image`. + +--- + +- contentType +- `string` +- The MIME type of the file. + +--- + +- name +- `string` +- The name of the file. + +--- + +- createdDate +- `string` +- The date and time the file was created. + +--- + +- modifiedDate +- `string` +- The date and time the file was last modified. + +--- + +- owner +- `string` +- The id of the user who owns the file. + +--- + +- notes +- `string` +- The notes associated with the file. + +--- + +- fileHref +- `string` +- The URL of the file. + +{% /table %} diff --git a/src/docs/version_002/resources/files/example.md b/src/docs/version_002/resources/files/example.md index 19f34b0..722b161 100644 --- a/src/docs/version_002/resources/files/example.md +++ b/src/docs/version_002/resources/files/example.md @@ -1 +1,18 @@ -# The File Info Object +# The File Information Object + +{% code heading="FILE INFORMATION" defaultLanguage="json" %} + +```json +{ + "type": "Attachment", + "contentType": "text/plain", + "name": "Test Attachment.txt", + "createdDate": "2021-12-13T21:34:14.519Z", + "modifiedDate": "2021-12-13T21:34:19.236Z", + "owner": "e7d20e9e-0bce-40e2-8fdb-f8c839a982cb", + "notes": "", + "fileHref": "https://api.onspring.dev/files/record/1/field/6989/file/89/file" +} +``` + +{% /code %} diff --git a/src/docs/version_002/resources/files/get_file_by_id/copy.md b/src/docs/version_002/resources/files/get_file_by_id/copy.md index 89b0862..891e091 100644 --- a/src/docs/version_002/resources/files/get_file_by_id/copy.md +++ b/src/docs/version_002/resources/files/get_file_by_id/copy.md @@ -1 +1,31 @@ # Get File by Id {% #get-file-by-id %} + +This endpoint returns the file with the given id. + +## Path Parameters + +{% table %} + +- Parameter Name +- Data Type +- Description + +--- + +- recordId +- `number` +- The id of the record that contains the file. + +--- + +- fieldId +- `number` +- The id of the field that contains the file. + +--- + +- fileId +- `number` +- The id of the file. + +{% /table %} diff --git a/src/docs/version_002/resources/files/get_file_by_id/example.md b/src/docs/version_002/resources/files/get_file_by_id/example.md index f9e6e6b..3649eeb 100644 --- a/src/docs/version_002/resources/files/get_file_by_id/example.md +++ b/src/docs/version_002/resources/files/get_file_by_id/example.md @@ -1 +1,87 @@ # Retrieve a file by it's id + +{% code method="GET" heading="/Files/recordId/{recordId}/fieldId/{fieldId}/fileId/{fileId}/file" defaultLanguage="bash" %} + +```bash +curl --location 'https://api.onspring.com/Files/recordId/1/fieldId/6989/fileId/89/file' \ +--header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' +``` + +```csharp +using Onspring.API.SDK; + +var onspringClient = new OnspringClient( + config.BaseUrl, + config.ApiKey +); + +var getFileResponse = await onspringClient.GetFileAsync(1, 6989, 89); + +using (var result = getFileResponse.Value) +{ + Console.WriteLine($"FileName is: {result.FileName}"); + Console.WriteLine($"ContentType: {result.ContentType}"); + Console.WriteLine($"ContentLength: {result.ContentLength}"); + + using (var fileStream = new FileStream($"C:\Users\Public\Documents\{result.FileName}", FileMode.Create)) + { + result.Stream.CopyTo(fileStream); + } +} +``` + +```javascript +import { OnspringClient } from 'onspring-api-sdk'; +import dotenv from 'dotenv'; +import fs from 'fs'; +dotenv.config(); + +const client = new OnspringClient( + process.env.BASE_URL, + process.env.API_KEY +); + +const res = await client.getFileById(1, 6989, 89); +const file = res.data; + +console.log(file.contentLength); +console.log(file.contentType); +console.log(file.fileName); +file.stream.pipe(fs.createWriteStream(file.fileName)); +``` + +```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.GetFileById(recordId=1, fieldId=6989, fileId=89) + +print(f'Status Code: {response.statusCode}') +print(f'Name: {response.data.file.name}') +print(f'Content Type: {response.data.file.contentType}') +print(f'Content Length: {response.data.file.contentLength}') + +filePath = f'C:\\Users\\sfree\\Documents\\Temp\\{response.data.file.name}' + +with open(filePath, "wb") as file: + file.write(response.data.file.content) + +print(f'File Location: {filePath}') +``` + +{% /code %} + +{% code heading="RESPONSE" defaultLanguage="text" %} + +```text +this is only a test +``` + +{% /code %} diff --git a/src/docs/version_002/resources/files/get_file_info_by_id/copy.md b/src/docs/version_002/resources/files/get_file_info_by_id/copy.md index 075508d..98487d2 100644 --- a/src/docs/version_002/resources/files/get_file_info_by_id/copy.md +++ b/src/docs/version_002/resources/files/get_file_info_by_id/copy.md @@ -1 +1,31 @@ # Get File Info by Id {% #get-file-info-by-id %} + +This endpoint returns information about the given file. + +## Path Parameters + +{% table %} + +- Parameter Name +- Data Type +- Description + +--- + +- recordId +- `number` +- The id of the record that contains the file. + +--- + +- fieldId +- `number` +- The id of the field that contains the file. + +--- + +- fileId +- `number` +- The id of the file. + +{% /table %} diff --git a/src/docs/version_002/resources/files/get_file_info_by_id/example.md b/src/docs/version_002/resources/files/get_file_info_by_id/example.md index 84ff571..d971957 100644 --- a/src/docs/version_002/resources/files/get_file_info_by_id/example.md +++ b/src/docs/version_002/resources/files/get_file_info_by_id/example.md @@ -1 +1,73 @@ # Retrieve a file's information by it's id + +{% code method="GET" heading="/Files/recordId/{recordId}/fieldId/{fieldId}/fileId/{fileId}" defaultLanguage="bash" %} + +```bash +curl --location 'https://api.onspring.com/Files/recordId/1/fieldId/6989/fileId/89' \ +--header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' +``` + +```csharp +using Onspring.API.SDK; + +var onspringClient = new OnspringClient( + config.BaseUrl, + config.ApiKey +); + +var response = await onspringClient.GetFileInfoAsync(1, 6989, 89); + +Console.WriteLine($"{response.Value.Name}, {response.Value.ContentType}"); +``` + +```javascript +import { OnspringClient } from 'onspring-api-sdk'; +import dotenv from 'dotenv'; +dotenv.config(); + +const client = new OnspringClient( + process.env.BASE_URL, + process.env.API_KEY +); + +const res = await client.getFileInfoById(1, 6989, 89); +const fileInfo = res.data; + +console.log(fileInfo); +``` + +```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.GetFileInfoById(recordId=1, fieldId=6989, fileId=89) + +print(f'Name: {response.data.fileInfo.name}') +print(f'Content Type: {response.data.fileInfo.contentType}') +``` + +{% /code %} + +{% code heading="RESPONSE" defaultLanguage="json" %} + +```json +{ + "type": "Attachment", + "contentType": "text/plain", + "name": "Test Attachment.txt", + "createdDate": "2021-12-13T21:34:14.519Z", + "modifiedDate": "2021-12-13T21:34:19.236Z", + "owner": "e7d20e9e-0bce-40e2-8fdb-f8c839a982cb", + "notes": "", + "fileHref": "https://api.onspring.dev/files/record/1/field/6989/file/89/file" +} +``` + +{% /code %}