The document_folder_id parameter in the Documents API create/update endpoints is not working correctly. All documents are created in the root folder (ID 0) regardless of the document_folder_id value sent.
Affected Endpoints
Root Cause
In /api/v1/documents/document_model.php on line 39, there is a typo that reads from the wrong POST parameter:
Current Code (Broken)
$$
if (isset($POST['document_folder_id'])) {
$folder = intval($POST['document_content']); // BUG: reads document_content instead
} elseif (isset($document_row) && isset($document_row['document_folder_id'])) {
$folder = intval($document_row['document_folder_id']);
} else {
$folder = 0;
}
$$
Steps to Reproduce
Send API request to create a document with document_folder_id set to a valid folder ID (e.g., 130)
Include document_content with HTML content
Check the created document's folder location
Example API Request
$$
POST /api/v1/documents/create.php
{
"api_key": "...",
"document_name": "Test Document",
"document_content": "<p>Test content</p>",
"document_folder_id": "130",
"client_id": "1"
}
$$
Expected Behavior
Document should be created in folder ID 130.
Actual Behavior
Document is created in folder ID 0 (root) because:
Fix
Change line 39 in /api/v1/documents/document_model.php from:
$$
$folder = intval($_POST['document_content']);
$$
To:
$$
$folder = intval($_POST['document_folder_id']);
$$
Impact
This bug affects any API integration that attempts to organize documents into folders. All documents end up in root regardless of the specified folder ID.
ITFlow Version
Testing on current production instance. Database schema confirms document_folder_id is the correct column name in the documents table.