Files [v2]
Contents
List Files
Endpoint:
URL |
|
Method |
|
Expected response code |
|
Expected response type |
|
Example:
curl -v \
-H "Authorization: apikey $API_USER:$API_KEY" \
$COREDATA_BASE_URL/api/v2/files/
Example response:
List Favourite Files
See User home | List-favourite-Files.
Get File details
Show details about an existing File.
Endpoint:
URL |
|
Method |
|
Expected response code |
|
Expected response type |
|
URL parameters:
file_id– is a File ID (UUID).
Example:
file_id=e139a8ac-7368-11ee-b992-57663b1559fb
curl -v \
-H "Authorization: apikey $API_USER:$API_KEY" \
$COREDATA_BASE_URL/api/v2/files/$file_id/
Example response:
Download File content
Endpoint:
URL |
|
Method |
|
Expected response code |
|
URL parameters:
file_id– is the ID of theFileto download content from.
Example:
file_id=e139a8ac-7368-11ee-b992-57663b1559fb
curl -v \
-H "Authorization: apikey $API_USER:$API_KEY" \
$COREDATA_BASE_URL/api/v2/files/$file_id/content/
In response it is expected to get code 302 Found, and the Location header should contain the direct link to the File content like this:
Location: https://tenant.coredata.is/laika/103d0b48a25b4197bb3b90bc462abc29?response-content-disposition=%20attachment%3B%20filename%2A%3Dutf-8%27%27sample.pdf&response-content-type=application%2Fpdf&AWSAccessKeyId=s3f%3Amyuser&Expires=1698326799&Signature=3TfPcpCwS8FrZExv%2FHfzERYFXAA%3D
The URL above should be used to download the content like this:
curl -v \
"https://tenant.coredata.is/laika/103d0b48a25b4197bb3b90bc462abc29?response-content-disposition=%20attachment%3B%20filename%2A%3Dutf-8%27%27sample.pdf&response-content-type=application%2Fpdf&AWSAccessKeyId=s3f%3Amyuser&Expires=1698326799&Signature=3TfPcpCwS8FrZExv%2FHfzERYFXAA%3D"
The request above should return the content itself and the headers like these:
...
< Content-Type: application/pdf
< Content-Length: 3028
< Last-Modified: Wed, 25 Oct 2023 19:01:17 GMT
< Content-Disposition: attachment; filename*=utf-8''sample.pdf
< Accept-Ranges: bytes
Create File
Create a File in a Project, Folder or Filespace.
Create File by uploading content to CoreData
Endpoint:
URL |
|
Method |
|
Content-Type |
|
Expected response code |
|
The endpoint accepts the following parameters:
Parameter | Type | Description | Mandatory |
|---|---|---|---|
|
| The binary content of the file. Example: | Yes |
|
| The name of the file to be uploaded. Example: | Yes |
|
| The title of the File. Filename without ending. Example: | Yes |
|
| ID of the parent, e.g. of a | Yes |
|
| Name of the | No |
|
| A comma separated list of contact IDs. Requires | No |
|
| A comma separated list of tags. Example: | No |
Response Location header contains URL of newly created File. The ID of the File can be derived from the Location, for example in a File URL [...]/api/v2/files/389a5280-8efc-11e6-a6e0-2f4ee7e36368/, the 389a5280-8efc-11e6-a6e0-2f4ee7e36368 is the ID of the created File.
Selecting a dynatype is optional, if no parameter is provided, then CoreData will use the dynatype File by default. Some predefined dynatype for files are:
FileContractLetterInLetterOutMemoOtherReport
The contacts will not be linked with the file if File dynatype is used.
Example:
filename=sample.pdf
filepathname=~/sample.pdf
title="Sample document"
parent=313ae0be-71cf-11ee-b1e9-ebd554949e29
curl -v \
-X POST \
-H "Authorization: apikey $API_USER:$API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "content=@$filepathname" \
-F "filename=$filename" \
-F "title=$title" \
-F "parent=$parent" \
$COREDATA_BASE_URL/api/v2/files/
Where:
filepathname– path and name of a local file to upload;filename– the name of the newFileto be created in CoreData;title– the title of the newFileto be created in CoreData;parent– the container in of the newFile, can be ID of eitherFilespace,ProjectorFolder.
The response contains Location header which looks like this:
Location: /api/v2/files/cb2cca52-7422-11ee-91ce-dff1c719d262/
Where the value of the reader contains the newly created file’s URL path on the target CoreData instance. The new File’s ID cb2cca52-7422-11ee-91ce-dff1c719d262 can be extracted from the Location header value.
For more information see:
Create File by uploading content directly to document storage server
The upload of file content directly to document storage server includes 3 steps which are described in details below. Here is an example combining all steps, creating a file within a project:
# Step 1 – Create a new BLOB.
# Note that a v3 endpoint is used to upload file content.
# There is no such alternative in v2.
filepathname=sample.pdf
content_length=$(stat -f%z "$filepathname")
content_type=application/pdf
blob_info=$(curl -v \
-X POST -G \
-H "Authorization: apikey $API_KEY" \
--data-urlencode "content_type=$content_type" \
--data-urlencode "content_length=$content_length" \
$COREDATA_BASE_URL/api/v3/blob/presigned-upload-url/)
blob_name=$(echo $blob_info | jq .blobName | tr -d '"')
presigned_url=$(echo $blob_info | jq .presignedUrl | tr -d '"')
# Step 2 – Upload file content to storage backend
curl -v \
-X PUT \
-H "Content-Type: $content_type" \
-H "Slug: $filename" \
--data-binary "@$filepathname" \
$presigned_url
# Step 3 – Create file
title="Sample document"
project_id=01350bc0-7971-11ee-bf90-138377a015b3
curl -v \
-X POST \
-H "Authorization: apikey $API_USER:$API_KEY" \
-H "Content-Type: multipart/form-data" \
-F "blob_name=$blob_name" \
-F "filename=$filename" \
-F "title=$title" \
-F "parent=$project_id" \
$COREDATA_BASE_URL/api/v2/files/
The previous example is explained in details below.
Step 1 – Create a new BLOB
First create a new BLOB via Files [v3] | Create-File-BLOB and get a response with a JSON like this:
{
"blobName": "98c59d020fe547b08cd0df36b1c01b37",
"presignedUrl": "https://home.coredata.is/laika/98c59d020fe547b08cd0df36b1c01b37?AWSAccessKeyId=s3f%3Amyuser&Expires=1698929283&Signature=vjbmLRn1MjwLVAuYRP8pY9TvNtc%3D"
}
Where:
presignedUrl– field containing a URL for file content upload used on Step 2 – Upload file content to storage backend below.blobName– contains the newly createdBLOBname used on Step 3 – Create file below.
Step 2 – Upload file content to storage backend
Using the presignedUrl obtained on the previous step Step 1 – Create a new BLOB, here we should upload file content directly to storage backend. The presignedUrl directs to the following endpoint:
URL |
|
Method |
|
Content-Type | MIME type of the BLOB |
Expected response code |
|
Step 3 – Create file
Using the Create File endpoint described above create a new File. The only exception is that instead of the content parameter the blob_name should be provided which must contain value of blobName obtained earlier on Step 1 – Create a new BLOB above.
Update File metadata
This endpoint allows editing of a File’s metadata, not its content.
Endpoint:
URL |
|
Method |
|
Content-Type |
|
Expected response code |
|
URL parameters:
file_id– is a placeholder for an existingFileID.
The endpoint accepts a JSON with the following fields:
Parameter | Type | Description | Mandatory |
|---|---|---|---|
|
| The name of the file to be uploaded. Example: | Yes |
|
| The title of the File. Filename without ending. Example: | Yes |
|
| The uuid of the parent, e.g. of a | Yes |
|
| Name of the | No |
|
| A comma separated list of contact UUIDs. Example: | No |
|
| A comma separated list of tags. Example: | No |
Example:
file_id=a3ddc64a-7422-11ee-b596-6b440b17d53b
title="Sample document (updated)"
filename=sample-updated.pdf
parent=30bdbf12-71cf-11ee-a5ea-a7771304e664
curl -v \
-X PUT \
-H "Authorization: apikey $API_USER:$API_KEY" \
-H "Content-Type: application/json" \
-d "{\"title\": \"$title\", \"filename\": \"$filename\", \"parent\": \"$parent\"}" \
$COREDATA_BASE_URL/api/v2/files/$file_id/
Where:
file_id– ID of aFileto update metadata for;title– newFiletitle to set;filename– new filename for theFile;parent– ID of theFile’s parent to set, the file will be moved if another parent ID is be specified.
Update File content
Update content of an existing File.
Endpoint:
URL |
|
Method |
|
Content-Type |
|
Expected response code |
|
URL parameters:
file_id– ID of an existingFile;filename– the name of a file to be uploaded (optional, if file extension is changed during re-upload then the new extension is taken fromfilenameparameter).
URL optional parameters:
snapshot_id– document version to update. Is used for document version control, the upload operation will fail if the last documentsnapshot_idon the backend differs from the values passed in the parameter;blob_name– name of pre-uploaded content, see Files [v3] | Create-File-BLOB (requiresdigestparameter to be passed as well, see below);digest– digest of the pre-uploaded content, must be used together with theblob_nameparameter.
Request body must contain the new file content to upload if no blob_name parameter is provided.
Example via uploading file content to CoreData
Example:
file_id=a3ddc64a-7422-11ee-b596-6b440b17d53b
filename=sample.pdf
filepathname=~/$filename
curl -v \
-X PUT -G \
-H "Authorization: apikey $API_USER:$API_KEY" \
-H "Content-Type: application/octet-stream" \
--data-binary "@$filepathname" \
$COREDATA_BASE_URL/api/v2/files/$file_id/content/?filename=$filename
Where:
file_id– ID of aFileto upload content for;filename– new filename for theFile;filepathname– path and name of a local file to upload content from.
The response contains useful headers, here are some of them:
X-Coredata-fields-filedigest: d41d8cd98f00b204e9800998ecf8427e– the uploaded content’s digest to check;X-Coredata-fields-snapshot-id: 25d74cea-7430-11ee-91ce-b785f71967fe– the newFileversion’s snapshot ID.
Example via uploading file content to storage server
Example:
# Step 1 – Create a new BLOB.
# Note that a v3 endpoint is used to upload file content.
# There is no such alternative in v2.
filename=sample.pdf
filepathname=~/$filename
content_length=$(stat -f%z "$filepathname")
content_type=application/pdf
blobInfo=$(curl -v \
-X POST -G \
-H "Authorization: apikey $API_KEY" \
--data-urlencode "content_type=$content_type" \
--data-urlencode "content_length=$content_length" \
$COREDATA_BASE_URL/api/v3/blob/presigned-upload-url/)
# Step 2 – Upload file content to storage backend
blob_name=$(echo $blobInfo | jq .blobName | tr -d '"')
presigned_url=$(echo $blobInfo | jq .presignedUrl | tr -d '"')
curl -v \
-X PUT \
-H "Content-Type: $content_type" \
-H "Slug: $filename" \
--data-binary "@$filepathname" \
$presigned_url
# Step 3 – Update content of existing file
file_id=58321016-8796-11ee-bd02-83c3e72c591e
filedigest=`openssl md5 $filepathname | awk '{print $2}'`
curl -v \
-X PUT \
-H "Authorization: apikey $API_USER:$API_KEY" \
"$COREDATA_BASE_URL/api/v2/files/$file_id/content/?blob_name=$blob_name&digest=$filedigest"
Delete File
Delete an existing File.
Endpoint:
URL |
|
Method |
|
Expected response code |
|
URL parameters:
file_id– the ID of an existingFileto delete.
Example:
file_id=e139a8ac-7368-11ee-b992-57663b1559fb
curl -v \
-X DELETE \
-H "Authorization: apikey $API_USER:$API_KEY" \
$COREDATA_BASE_URL/api/v2/files/$file_id/
List Files in a Project
Get list of files in a project.
Endpoint:
URL |
|
Method |
|
Expected response code |
|
Expected response type |
|
URL parameters:
project_id– ID of an existing project to get list of files from.
Example:
project_id=3122576a-71cf-11ee-848e-b7be3292bc02
curl -v \
-H "Authorization: apikey $API_USER:$API_KEY" \
$COREDATA_BASE_URL/api/v2/projects/$project_id/files/
Example response: