User guide
Quick Start Guide
Dashboard
Overviews
Case detail (Caseoverview)
Case - event
Tasks
Case notes
Documents
User settings
Favorites
Table component
FAQ
News/Announcements in Team assistant
Mobile app settings
Administrator Guide
Platform guide
Administration
Crons
Authentication and Synchronization
Mobile App Setup for Your Environment
Scheme
Dynamic tables
Archiving
Scripts
Service console
Scheduled Tasks
HR Agenda
Sequences
CSP Headers
Logs
Access Token Settings & Session Expiration
Template
Roles
Planning
Users
Organizational structure
Events
Translations
AXIOS API
Calculations & Functions
Integrations
TAS Forms
TAS Forms
Activating the module on the environment
TAS Forms - secret creation guide for Docker Swarm
Advanced Features & Tips
Partners
Product
Technical Changelog
Business Changelog
Version Upgrade Guide
Upgrading to 5.9
Upgrading to 5.3
Dynamic conditions migration
PDF printing adjustment
Editing Task Description vs Task Instructions
Transpiling forEach to a for loop
Rendering HTML on Caseoverview
Upgrading to 5.7
Lodash upgrade v4.17.x (>v5.5)
Main changes and deprecated features (v5.3 > v5.7)
Highlighting variables in Read-only status (>v5.7.58)
Using validation functions
Differences between TAS4 and TAS5 - a complete overview
Best Practices for Upgrading from v4 to v5
Technical details
News / Important information
- All Categories /
- Partners
- 📄Template Implementation (Consulting)
- Implementation know-how /
- Sending Documents via API
Sending Documents via API
This documentation provides a detailed guide on how to send documents from Team Assistant (TAS) via the API. The process involves retrieving document IDs from the Team Assistant storage system, exporting the documents, encoding them if necessary, and then sending them to an external system using an API request.
- Depending on the API integration, the document can be retrieved as a physical file or base64-encoded content.
Key Functions in the Process
1. Retrieving Documents
To send a document, the first step is to extract the document from the Team Assistant storage system. This involves fetching the document ID and retrieving its content in a format suitable for transmission.
- The document ID can be retrieved using a query to the Team Assistant DMS.
- Depending on the API integration, the document can be retrieved as a physical file or base64-encoded content.
- If required, the file is temporarily stored in a designated location before being processed.
2. Preparing the Document for Transfer
Once retrieved, the document may require additional processing:
- Base64 Encoding: If the API expects a base64 string, the document content is encoded accordingly.
- File Name Assignment: Ensuring each document is properly named before sending.
- Multiple File Handling: If multiple documents need to be sent, they are stored in an array before being uploaded.
3. Sending Documents via API
After processing, the document is sent to the external system via an API request. This involves:
- Constructing the API endpoint URL.
- Configuring HTTP request headers, such as authentication tokens and content type.
- Attaching the document (either as a file or as a base64 string) to the request body.
- Sending the request using a method such as HTTP POST.
- Handling the API response to confirm a successful transfer.
4. Error Handling and Logging
To ensure smooth operation, error handling mechanisms should be in place:
- Validating that the document ID exists before attempting to retrieve content.
- Checking that the API response returns a successful status code.
- Logging errors and warnings if the document upload fails.
- Implementing retries in case of temporary failures.
Code examples
Physical file
/**
* Sends an attached document related to a specific case.
*
* @param {string} documentToSend - The actual name of the document attached to the case.
* @param {string} docNameTarget - Name of the document that you want receiving software to see.
*/
function sendDocument(documentToSend, docNameTarget) {
const dmsEntity = storage.getDmsEntity(documentToSend);
const {
NAME: fileName,
DMSF_ID: doc_id
} = dmsEntity;
if (fileName.toLowerCase().indexOf('.pdf') == -1) debug.error('pdf file only');
const finalFileName = `${docNameTarget}.pdf`;
const tmp = storage.getTmpLibrary();
const {
name
} = tmp.fileSync();
const filePath = `${name}_${finalFileName}`;
proc.warn(`tmp file path: ${filePath}`);
lib.exportAttachment(documentToSend, filePath);
curl.start();
curl.setOpt('URL', 'https://your.url/api/document/add');
curl.setOpt('CUSTOMREQUEST', 'POST');
curl.setOpt('FOLLOWLOCATION', true);
curl.setOpt('FAILONERROR', false);
curl.setOpt('SSL_VERIFYPEER', false);
curl.setOpt('SSL_VERIFYHOST', false);
curl.setOpt('TIMEOUT', 300);
curl.setOpt('HTTPHEADER', [
`Authorization: Bearer xxx`,
`accept: application/json`,
`Content-Type: multipart/form-data`
]);
curl.setOpt('HTTPPOST', [{
name: 'Files',
file: filePath,
type: 'application/pdf'
}]);
const response = curl.perform();
return response;
}
Base64-encoded content
var fileId = lib.getDMSFileIds('*', ',')
var files = [];
// Create a new Array, with name and content of each file
fileId = fileId.split(',');
for (var i = 0; i < fileId.length; i++) {
var fileContent = storage.getDmsContent(fileId[i], 'base64');
var fileName = variableFileNames[i];
if (fileName) {
files.push({ fileName, fileContent }); } }
var base64String = '';
var namesString = '';
for (let i = 0; i < files.length; i++) {
if (i > 100) {
break;
}
if (i === 0) {
if (typeof files[i]['fileContent'] == 'object') {
base64String = files[i]['fileContent'].toString('base64');
} else {
base64String = files[i]['fileContent']; }
Updated
by Anna Gernát