diff --git a/src/docs/version_002/resources/files/add_file/copy.md b/src/docs/version_002/resources/files/add_file/copy.md index 7f951f7..fd122ea 100644 --- a/src/docs/version_002/resources/files/add_file/copy.md +++ b/src/docs/version_002/resources/files/add_file/copy.md @@ -1 +1,59 @@ # Add File {% #add-file %} + +This endpoint allows you to add a file to a record. The request body must be a multipart form data request. + +## Request Body Properties + +{% table %} + +- Property Name +- Data Type +- Description + +--- + +- recordId +- `number` +- The id of the record to which the file will be added. + +--- + +- fieldId +- `number` +- The id of the field to which the file will be added. + +--- + +- notes +- `string` +- The notes to be added to the file. + +--- + +- modifiedDate +- `string` +- The date the file was last modified. + +--- + +- file +- `binary` +- The file to be added. + +{% /table %} + +## Response Body Properties + +{% table %} + +- Property Name +- Data Type +- Description + +--- + +- id +- `number` +- The id of the file that was added. + +{% /table %} diff --git a/src/docs/version_002/resources/files/add_file/example.md b/src/docs/version_002/resources/files/add_file/example.md index f11d463..812a7a1 100644 --- a/src/docs/version_002/resources/files/add_file/example.md +++ b/src/docs/version_002/resources/files/add_file/example.md @@ -1 +1,109 @@ # Add a file to a record + +{% code method="POST" heading="/Files" defaultLanguage="bash" %} + +```bash +curl --location 'https://api.onspring.com/Files' \ +--header 'X-ApiKey: 000000ffffff000000ffffff/00000000-ffff-0000-ffff-000000000000' \ +--form 'recordId="140"' \ +--form 'fieldId="6989"' \ +--form 'notes="Updating record with attachment."' \ +--form 'modifiedDate=""' \ +--form 'file=@"test-attachment.txt"' +``` + +```csharp +using Onspring.API.SDK; +using Onspring.API.SDK.Models; +using System.IO; + +var onspringClient = new OnspringClient( + config.BaseUrl, + config.ApiKey +); + +var filePath = "test-attachment.txt"; +var saveFileRequest = new SaveFileRequest +{ + FieldId = 6989, + RecordId = 140, + FileStream = File.OpenRead(filePath), + FileName = Path.GetFileName(filePath), + ModifiedDate = DateTime.UtcNow, + Notes = "Updating record with attachment.", + ContentType = "text/plain" +}; + +var saveResponse = await onspringClient.SaveFileAsync(saveFileRequest); +Console.WriteLine($"New File Id is: {saveResponse.Value.Id}"); +``` + +```javascript +import { + OnspringClient, + SaveFileRequest, +} 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 request = new SaveFileRequest( + 140, + 6989, + 'notes', + new Date(), + 'test-attachment.txt', + 'text/plain', + fs.createReadStream('test-attachment.txt') +); + +const res = await client.saveFile(request); +const fileId = res.data.id; + +console.log(fileId); +``` + +```python +from OnspringApiSdk.OnspringClient import OnspringClient +from OnspringApiSdk.Models import SaveFileRequest +from configparser import ConfigParser + +cfg = ConfigParser() +cfg.read('config.ini') + +key = cfg['prod']['key'] +url = cfg['prod']['url'] + +client = OnspringClient(url, key) +request = SaveFileRequest( + recordId=140, + fieldId=6989, + fileName='test-attachment.txt', + filePath='test-attachment.txt', + contentType='text/plain', + notes='Updating record with attachment.', + modifiedDate=datetime.now() +) + +response = client.SaveFile(request) + +print(f'Status Code: {response.statusCode}') +print(f'File Id: {response.data.id}') +``` + +{% /code %} + +{% code heading="RESPONSE" defaultLanguage="json" %} + +```json +{ + "id": 1904 +} +``` + +{% /code %} diff --git a/src/docs/version_002/resources/files/delete_file_by_id/example.md b/src/docs/version_002/resources/files/delete_file_by_id/example.md index a987edc..78d01dd 100644 --- a/src/docs/version_002/resources/files/delete_file_by_id/example.md +++ b/src/docs/version_002/resources/files/delete_file_by_id/example.md @@ -1 +1,21 @@ # Deleting a file by it's id + +{% code method="DELETE" heading="/Files/recordId/{recordId}/fieldId/{fieldId}/fileId/{fileId}/file" defaultLanguage="bash" %} + +```bash + +``` + +```csharp + +``` + +```javascript + +``` + +```python + +``` + +{% /code %}