Skip to content

Download file

Endpoint

GET /organizations/{org_id}/file/{file_id}/dl

This endpoint downloads the actual content of a file (asset) that was previously uploaded (e.g., via a task form field or kick-off field).

Note the /dl suffix, which distinguishes this from potentially getting file metadata.

Request

Replace {org_id} with your Organization ID and {file_id} with the Asset ID of the file you want to download (this ID is obtained when uploading the file or potentially from getting task/process data).

Headers

  • Authorization: Bearer {your_access_token}
  • X-Tallyfy-Client: APIClient
  • (Accept header might be omitted or set based on expected file type, but the API primarily controls the response Content-Type)

Code Samples

These samples demonstrate how to fetch the file content and save it locally. Error handling should check the response status and Content-Type header.

const accessToken = 'YOUR_PERSONAL_ACCESS_TOKEN';
const orgId = 'YOUR_ORGANIZATION_ID';
const fileId = 'ASSET_ID_TO_DOWNLOAD';
const apiUrl = `https://go.tallyfy.com/api/organizations/${orgId}/file/${fileId}/dl`;
const localFilename = 'downloaded_file'; // Desired local filename
const headers = new Headers();
headers.append('Authorization', `Bearer ${accessToken}`);
headers.append('X-Tallyfy-Client', 'APIClient');
fetch(apiUrl, {
method: 'GET',
headers: headers
})
.then(response => {
if (!response.ok) {
// Try to read error as text, might not be JSON
return response.text().then(text => {
throw new Error(`HTTP error! status: ${response.status}, message: ${text}`);
});
}
// Get filename from Content-Disposition header if available
const disposition = response.headers.get('content-disposition');
let filename = localFilename;
if (disposition && disposition.indexOf('attachment') !== -1) {
const filenameRegex = /filename[^;=\n]*=((['"])(.*?)\2|[^;\n]*)/;
const matches = filenameRegex.exec(disposition);
if (matches != null && matches[3]) {
filename = matches[3].replace(/[^\w\.\-]/g, '_'); // Basic sanitization
}
}
console.log(`Attempting to download as: ${filename}`);
return response.blob().then(blob => ({ blob, filename }));
})
.then(({ blob, filename }) => {
// Create a link element to trigger the download in the browser
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
a.remove();
console.log('File download initiated.');
})
.catch(error => {
console.error('Error downloading file:', error);
});

Response

A successful request returns a 200 OK status code. The response body is the raw file content, not JSON.

  • The Content-Type header indicates the MIME type of the file (e.g., image/png, application/pdf).
  • The Content-Disposition header often suggests a filename (e.g., attachment; filename="report.pdf"). Your code should parse this header to save the file with its original name if desired.

If the file ID is invalid or access is denied, an appropriate error status code (404, 403) will be returned, likely with an error message in the body (which might be JSON or plain text).