diff --git a/src/BoxClient.php b/src/BoxClient.php index 4761d43..3adf78a 100644 --- a/src/BoxClient.php +++ b/src/BoxClient.php @@ -247,45 +247,48 @@ class BoxClient */ public function setCustomMetadata($fileId, $metadata) { - // Create simplified metadata (full JSON is too large for Box) - $simplifiedMetadata = [ - 'asset_id' => $metadata['asset_id'] ?? 'Unknown', - 'name' => $metadata['name'] ?? 'Unknown', - 'mime_type' => $metadata['mime_type'] ?? 'Unknown', - 'file_size' => $metadata['file_size'] ?? 0 - ]; - - $metadataJson = json_encode($simplifiedMetadata); + // TEST: Send minimal string value to verify template works + $testValue = "Test metadata - Asset ID: " . ($metadata['asset_id'] ?? 'Unknown'); // Apply metadata template to file - // Template from user: https://oliver-na.app.box.com/master/metadata/templates/ferrerodammetadata + // Template: https://oliver-na.app.box.com/master/metadata/templates/ferrerodammetadata $templateScope = 'enterprise'; $templateKey = 'ferrerodammetadata'; - // Try different field name variations - $fieldVariations = [ - 'DAM-Metadata', - 'DAMMetadata', - 'damMetadata', - 'dam_metadata' + // Try with simple string value first + $metadataValues = [ + 'damMetadata' => $testValue // Start with camelCase (Box standard) ]; - foreach ($fieldVariations as $fieldName) { - $metadataValues = [$fieldName => $metadataJson]; + $endpoint = "/files/{$fileId}/metadata/{$templateScope}/{$templateKey}"; - $endpoint = "/files/{$fileId}/metadata/{$templateScope}/{$templateKey}"; + error_log("Box Metadata: Attempting POST to " . $endpoint); + error_log("Box Metadata: Values: " . json_encode($metadataValues)); + + $response = $this->apiRequest('POST', $endpoint, $metadataValues); + + if ($response['success']) { + error_log("Box Metadata: SUCCESS! Template applied"); + return true; + } + + error_log("Box Metadata: POST failed with: " . ($response['raw'] ?? 'Unknown')); + + // Try different field name variations if first attempt failed + $fieldVariations = ['DAMMetadata', 'DAM-Metadata', 'dam_metadata', 'metadata']; + + foreach ($fieldVariations as $fieldName) { + $metadataValues = [$fieldName => $testValue]; $response = $this->apiRequest('POST', $endpoint, $metadataValues); if ($response['success']) { error_log("Box Metadata: Success with field name: " . $fieldName); return true; } - - error_log("Box Metadata: Failed with field " . $fieldName . ": " . ($response['raw'] ?? 'Unknown')); } - // All attempts failed - use description - error_log("Box Metadata: All template attempts failed, using file description"); + // All attempts failed + error_log("Box Metadata: All template attempts failed"); // POST to create metadata instance on file $endpoint = "/files/{$fileId}/metadata/{$templateScope}/{$templateKey}"; diff --git a/src/DatabaseClient.php b/src/DatabaseClient.php index 2c275fb..d417ada 100644 --- a/src/DatabaseClient.php +++ b/src/DatabaseClient.php @@ -64,8 +64,9 @@ class DatabaseClient $pathInfo = pathinfo($assetData['name'] ?? 'unknown'); - // Store Box info and DAM upload folder ID - $description = "Box File ID: {$boxFileId}\nBox URL: {$boxUrl}\nDAM Asset ID: " . ($assetData['asset_id'] ?? 'Unknown'); + // Store Box info, DAM upload folder ID, and metadata JSON + $metadataJson = json_encode($assetData, JSON_PRETTY_PRINT); + $description = "Box File ID: {$boxFileId}\nBox URL: {$boxUrl}\nDAM Asset ID: " . ($assetData['asset_id'] ?? 'Unknown') . "\n\nDAM Metadata JSON:\n" . substr($metadataJson, 0, 5000); // Limit to 5KB $stmt->execute([ ':tracking_id' => $trackingId,