Using REST API to upload Documents *solved*

I have been struggling uploading images to my products through the POST /documents/upload API. My client kept getting back a 401 with the error:

{   
    "error": {
        "code": 401,
        "message": "Unauthorized"
    },
    "debug": {
        "source": "api_documents.class.php:580 at call stage",
        "stages": {
            "success": [
                "get",
                "route",
                "negotiate",
                "authenticate",
                "validate"
            ],
            "failure": [
                "call",
                "message"
            ]
        }
    }
}

Digging around in the server logs, I saw:

[Mon Dec 12 20:45:34.207351 2022] [php:warn] [pid 2373] [client 172.19.0.1:38206] PHP Warning:  Undefined property: stdClass::$ecm in /var/www/html/api/class/api_documents.class.php on line 579
[Mon Dec 12 20:45:34.207414 2022] [php:warn] [pid 2373] [client 172.19.0.1:38206] PHP Warning:  Attempt to read property "upload" on null in /var/www/html/api/class/api_documents.class.php on line 579

Looking through the code, I see the following:

if (!DolibarrApiAccess::$user->rights->ecm->upload) {
    throw new RestException(401);
}

ecm? Ah, it turns out I did not have the ECM module enabled, therefore ecm was null causing an exception to be thrown!

Enabling the ECM module now allows me to upload files to my products. It seems like this should either not require that check or the documentation should be updated to reflect the requirement of having the ECM module enabled!

Thanks for the awesome product!