- 29 Nov 2022
- 2 Minutes to read
- Print
- DarkLight
File Download Endpoint(POST)
- Updated on 29 Nov 2022
- 2 Minutes to read
- Print
- DarkLight
File Download Endpoint(POST)
Initial Preparation
File Download Endpoint is accessed through the url {{baseURL}}/CSSAPI/V2/Files/{{entityName}}/Download
- baseURL – your company’s ContractInsight URL
- entityName – name of the database table
The HTTP request type is POST. Content type for this request is set to applications/json.
Introduction
File Download Endpoint is designed to allow clients to download files associated with an entity. Things to keep in mind when making calls to UPDATE Endpoint:
- You can only download one file at a time.
- Request format for this endpoint is the same as for GET Endpoint. Except, field collection needs to be empty. Adding fields into collection might produce errors.
- OrderByTag and GroupByTag must be empty or skipped. Setting those properties to any values will cause REST API not able to execute the query and an exception will be returned.
- StartIndex and Length attributes will be ignored.
- In case when the Clause is written in a way that produces multiple files to be pulled from database, REST API returns first file it pulls from the table.
- Clause with rules is required to execute the query
- Successful response is of multipart/form-data format. It is composite: binary file and JSON object containing Contract ID, FileType, and FileName properties.
Request Format
Since OrderByTag, GroupByTag, StartIndex, and Length properties are not needed, they can be skipped.
Response
- Successful response is of multipart/form-data format. Response has two parts (highlighted are special delimiters called boundaries)
- Response of type application/octet-stream. Contains actual file bytes.
- Response of type application/json that contains an object describing the file
- Failed response varies depending on the error (no standard response is available)
More on Failed Response
1. When the clause criteria are syntactically correct, but the file is not found/pulled, the error may look like this:
2. Adding fields
- If the field list includes the one holding actual file, error shown in previous example will be returned
- If the field list doesn’t include the one holding actual file, the following error will occur:
3. When you attempt to configure OrderByTag and GroupByTag, an exception will be returned that is similar to the one below:
Downloading the file with Postman
When testing the endpoint with Postman, we will be getting response in the format described above. If we want to download the file, we need to expand the “Send” button and select “Send and Download” option:
When the request runs successfully, you will be prompted to save the file on your machine:
File Download Endpoint in Action
Task 1: Download file based on file name (partial file name)
In this example, we are downloading file from tblContractFiles
Request Body | Record in the database |
| |
Response (File part) | Response (JSON) |
|
Task 2: Download a File associated with a particular contract ID
Here, we are downloading a file without specifying file name or ID. The file is associated with a contract with ID of 2. Please Note that when the Clause produces more than one returned record, the first file will be returned.
Request Body | Record in the database |
| We have 2 files associated with ContractID 2. The first file added to the contract record is returned. In this case, the file is “Requirements.docx” |
Response (File part) | Respone (JSON) |
|