Search code examples
activecollab

ActiveCollab API - problem with attaching files


I was trying upload files (POST /upload-files) and attach it to a task (PUT /projects/x/tasks/x) with an array of codes I got after /upload-files.

'attach_uploaded_files' => ['xxxx', 'xxxx', ...]

Files was uploaded successfully. I can see them, open, download them on the projects page (files tab).

project page

But on the task window, attached files don't display, no preview, no full size image and they are not able to be downloaded. Could you help me please to understand why attached files don't display correctly, meanwhile they seem to be fine on the project page?

task window


Solution

  • The problem was that I was trying attach multiple codes to a task. To attach files to a task correctly you have to attach file by file.

    Incorrect:

    $params['attach_uploaded_files'] = ['code1', 'code2', 'code3'...];
    

    Correct:

    You need a loop.

    $params = [];
    $codes = ['code1', 'code2', 'code3'];
    
    foreach($codes as $code){
    $params['attach_uploaded_files'] = [$code];
    
    
    --PUT request to attach the file to a task--
    }