API calls related to file objects:
Retrieve
Return a single file
GET /api/v1/vaults/<vault_id>/files/<file_id>
Note: The contents are base64 encoded
Example
curl -H "X-CDD-Token: $TOKEN" -X GET "https://app.collaborativedrug.com/api/v1/vaults/<vault_id>/files/<file_id>"
Returns:
{
"id": 1069448031,
"class": "uploaded file",
"name": "tmp.txt",
"mime_type":
{
"synonyms": [],
"symbol": "text",
"string": "text/plain",
"hash": -1147906696977776415
},
"character_set": "US-ASCII",
"contents": "VGhpcyBpcyBhIGZpbGUK"
}
Following this up with:
echo VGhpcyBpcyBhIGZpbGUK | base64 -D
Returns:
This is a file
Note: "This is a file" is the actual content of this text file
Create
Attach a file to an object (Run, Molecule, Protocol or ELN entry)
POST /api/v1/vaults/<vault_id>/files
Example (adding a file to a Protocol Run)
curl -H "X-CDD-Token: $TOKEN" -X POST --form "file=@C:\files\<file_name>" --form "resource_class=run" --form "resource_id=<run_id>" "https://app.collaborativedrug.com/api/v1/vaults/<vault_id>/files"
Returns:
{
"id": "1069448044"
"name": "<file_name>"
}
Note: Additional allowed values for resource_class are "molecule", "protocol" and "eln_entry".
Example (adding a file to an ELN Entry)
curl -H "X-CDD-Token: $TOKEN" -X POST --form "file=@C:\files\<file_name>" --form "resource_class=eln_entry" --form "resource_id=<eln_entry_id>" "https://app.collaborativedrug.com/api/v1/vaults/<vault_id>/files"
Returns:
{
"id": "7395612976"
"name": "<file_name>"
}
Note: To add a file into an ELN entry, the entry must already exist. ELN Entries can be created (by Vault Administrators only) using the POST eln/entries API call.
Delete
Delete a file attachment
DELETE /api/v1/vaults/<vault_id>/files/<file_id>
Deletes a single file.
Example
curl -H "X-CDD-Token: $TOKEN" -X DELETE "https://app.collaborativedrug.com/api/v1/vaults/<vault_id>/files/<file_id>"
Returns:
{
"message": "File with ID <file_id> has been destroyed"
}