Download Worksheet Attachment (2)
Download Attachment
Overview
The Download Attachment endpoint retrieves a document stored in cieTrade and returns it as a binary file stream. The response will trigger a file download in the browser using the original document name as the filename. The document to be downloaded is identified by its unique document ID, which can be obtained from the ListWorksheetAttachment endpoint.
Endpoint Details
| Method | GET |
| URL | https://api.cietrade.net/DownloadWorksheetAttachment?UserID=Example@cietrade.com&DocID=50647 |
| Content-Type | Not required — parameters are passed via query string. |
Query String Parameters
This endpoint uses a GET request. All parameters are passed as query string values appended to the endpoint URL. There is no request body.
| Parameter | Type | Required | Description |
|---|---|---|---|
| UserID | String | Yes | Server token provided by cieTrade to identify the target server. |
| DocID | String | Yes | The unique identifier of the document to download. This value is returned by the ListWorksheetAttachment endpoint. |
Response
On success the endpoint returns the document as a binary file stream with a Content-Disposition header set to attachment. The browser will automatically trigger a file download using the original document name stored in cieTrade.
| Response | Description |
|---|---|
| Binary File Stream | The document file returned as a binary stream. The browser will trigger a download dialog using the original document name. |
| 404 Not Found | The document could not be found or there was an error retrieving it. The response body will contain a description of the error. |
Usage Note
Because this is a GET endpoint that returns a binary file stream, it cannot be called using a standard JSON fetch request with a request body. There are two recommended approaches for triggering the download from a web portal:
Option 1 - Direct browser navigation. Set the browser location directly to the endpoint URL with the query string parameters. The browser will handle the file download automatically.
Example:
window.location.href = 'https://api.cietrade.net/DownloadWorksheetAttachment?UserID=Example@cieTrade.com&DocID=50647';
Option 2 - Fetch with blob handling. Use a fetch call to retrieve the binary response, convert it to a blob, and programmatically trigger a download link in the browser.
fetch(fetchString, { method: 'GET' })
.then(function(response) { return response.blob(); })
.then(function(blob) {
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = 'filename';
document.body.appendChild(a);
a.click();
a.remove();
});