I contacted ActiveCollab support, who instructed me to create a post here.
We are running version 7.3.306 and need to upload a file/attachment via the API.
I have been referencing the API Documentation, which instructs me to do a POST to /upload-files
, then use the "code" from the response to attach it to a task in a subsequent POST to /projects/<PROJECT ID>/tasks
.
I've tried the curl request below, which returns a HTTP 200 with a body of []
instead of the expected response shown in the documentation.
curl --location 'https://<URL OF SELF HOSTED VERSION>/api/v7/upload-files' \
--header 'X-Angie-AuthApiToken: <WORKING TOKEN>' \
--header 'Content-Type: image/png' \
--data '@/path/to/test/png-test.png'
Thoughts on what am I missing?
Turned out to be an issue with the content type. Instead of sending the file as application/x-www-form-urlencoded
in the POST request, it needed to submitted as multipart/form-data
.
curl --location 'https://<URL OF SELF HOSTED VERSION>/api/v7/upload-files' \
--header 'X-Angie-AuthApiToken: <WORKING TOKEN>' \
--form 'file=@"/path/to/test/png-test.png"'
The curl command above returns JSON which contains a code for the file, which can be used to attach the file to a task:
curl --location 'https://<URL OF SELF HOSTED VERSION>/api/v7/projects/<PROJECT ID>/tasks' \
--header 'X-Angie-AuthApiToken: <WORKING TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"task_list_id": <TASK LIST ID>,
"project_id": <PROJECT ID>,
"name": "<NAME OF TASK>",
"body": "<BODY OF TASK>",
"attach_uploaded_files": [
"<UPLOADED FILE CODE>"
]
}'
Further reading on ReqBin explains the differences between the content types and appropriate curl syntax if you're interested.