Store DAM metadata JSON in database description field + test Box template

Database:
- Store full DAM metadata JSON in description field (5KB limit)
- Includes Box links and upload folder ID
- Full asset metadata preserved

Box Metadata Template Testing:
- Simplified to send just test string first
- Log endpoint and values being sent
- Try 5 field name variations
- Will identify correct field name from logs

Next test will show which field name works for Box template.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
DJP 2025-10-28 17:09:58 -04:00
parent 333f62c9e6
commit 2b42b4e42e
2 changed files with 29 additions and 25 deletions

View file

@ -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}";

View file

@ -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,