$configV3->getBaseUrl(), 'timeout' => $configV3->get('api.timeout'), 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json' ] ]; $collectionPath = __DIR__ . '/' . $configV3->get('postman_collection'); $testRunner = new TestRunner($collectionPath, $config); // Get campaign ID from URL or use default $campaignId = $_GET['campaign_id'] ?? '9697ffb1cc07b7c90ca0ea44ac44d3f6b01efa96'; $currentFolderId = $_GET['folder_id'] ?? null; $folderResults = null; $assetResults = null; $error = null; $success = null; if ($_GET['action'] === 'get_folders') { try { $apiClient = new ApiClient(); $apiClient->setBaseUrl($configV3->getBaseUrl()); $oauth2Handler = new ReflectionProperty($testRunner, 'oauth2Handler'); $oauth2Handler->setAccessible(true); $oauth2HandlerInstance = $oauth2Handler->getValue($testRunner); if ($oauth2HandlerInstance) { $apiClient->setHeader('Authorization', $oauth2HandlerInstance->getAuthHeader()); } // Get folders $request = [ 'method' => 'GET', 'url' => "/v6/folders/{$campaignId}/children?load_type=metadata" ]; $response = $apiClient->executeRequest($request); if ($response['success']) { $folderResults = json_decode($response['body'], true); } else { $error = "Failed to get folders: " . ($response['error'] ?? 'Unknown error'); } } catch (Exception $e) { $error = $e->getMessage(); } } if ($_GET['action'] === 'get_assets' && isset($_GET['folder_id'])) { try { $folderId = $_GET['folder_id']; $apiClient = new ApiClient(); $apiClient->setBaseUrl($configV3->getBaseUrl()); $oauth2Handler = new ReflectionProperty($testRunner, 'oauth2Handler'); $oauth2Handler->setAccessible(true); $oauth2HandlerInstance = $oauth2Handler->getValue($testRunner); if ($oauth2HandlerInstance) { $apiClient->setHeader('Authorization', $oauth2HandlerInstance->getAuthHeader()); } // Get assets from folder $request = [ 'method' => 'GET', 'url' => "/v6/folders/{$folderId}/children?load_type=metadata" ]; $response = $apiClient->executeRequest($request); if ($response['success']) { $assetResults = json_decode($response['body'], true); } else { $error = "Failed to get assets: " . ($response['error'] ?? 'Unknown error'); } } catch (Exception $e) { $error = $e->getMessage(); } } if ($_GET['action'] === 'delete_asset' && isset($_GET['asset_id'])) { try { $assetId = $_GET['asset_id']; $returnFolder = $_GET['folder_id'] ?? null; $apiClient = new ApiClient(); $apiClient->setBaseUrl($configV3->getBaseUrl()); $oauth2Handler = new ReflectionProperty($testRunner, 'oauth2Handler'); $oauth2Handler->setAccessible(true); $oauth2HandlerInstance = $oauth2Handler->getValue($testRunner); if ($oauth2HandlerInstance) { $apiClient->setHeader('Authorization', $oauth2HandlerInstance->getAuthHeader()); } // Delete asset $request = [ 'method' => 'DELETE', 'url' => "/v6/assets/{$assetId}" ]; error_log("DEBUG DELETE: Deleting asset $assetId"); $response = $apiClient->executeRequest($request); error_log("DEBUG DELETE: HTTP Code: " . ($response['http_code'] ?? 'N/A')); error_log("DEBUG DELETE: Response: " . substr($response['body'] ?? '', 0, 500)); // Check for successful HTTP codes (200, 204 No Content are typical for DELETE) if ($response['success'] && ($response['http_code'] == 200 || $response['http_code'] == 204)) { $success = "✅ Asset deleted successfully: $assetId"; error_log("DEBUG DELETE: SUCCESS"); // Redirect back to folder view if ($returnFolder) { header("Location: ?action=get_assets&folder_id=" . urlencode($returnFolder) . "&deleted=1"); exit; } } else { $errorDetail = $response['body'] ?? $response['error'] ?? 'Unknown error'; $error = "❌ Failed to delete asset (HTTP {$response['http_code']}): $errorDetail"; error_log("DEBUG DELETE: FAILED - $error"); } } catch (Exception $e) { $error = $e->getMessage(); } } if ($_GET['action'] === 'get_asset_direct' && isset($_GET['asset_id'])) { try { $assetId = $_GET['asset_id']; $apiClient = new ApiClient(); $apiClient->setBaseUrl($configV3->getBaseUrl()); $oauth2Handler = new ReflectionProperty($testRunner, 'oauth2Handler'); $oauth2Handler->setAccessible(true); $oauth2HandlerInstance = $oauth2Handler->getValue($testRunner); if ($oauth2HandlerInstance) { $apiClient->setHeader('Authorization', $oauth2HandlerInstance->getAuthHeader()); } // Get specific asset $request = [ 'method' => 'GET', 'url' => "/v6/assets/{$assetId}?load_type=full" ]; $response = $apiClient->executeRequest($request); error_log("DIRECT ASSET LOOKUP: Asset $assetId - HTTP " . $response['http_code']); if ($response['success'] && $response['http_code'] == 200) { $assetData = json_decode($response['body'], true); $success = "✅ Asset found: $assetId"; // Store for display $assetResults = ['direct_asset' => $assetData]; } else { $error = "❌ Asset not found: $assetId (HTTP {$response['http_code']})"; error_log("DIRECT ASSET LOOKUP: Response: " . substr($response['body'] ?? '', 0, 500)); } } catch (Exception $e) { $error = $e->getMessage(); } } $oauth2Status = $testRunner->getOAuth2Status(); ?>
Campaign Asset ID: = htmlspecialchars($campaignId) ?>
Use this to verify if an asset ID exists in the DAM (helps debug upload issues)
Found = count($folders) ?> folder(s)
Asset ID: = htmlspecialchars($folder['asset_id']) ?>
Type: = htmlspecialchars($folder['data_type'] ?? 'N/A') ?>
📂 Get Assets from This Folder= htmlspecialchars(json_encode($folderResults, JSON_PRETTY_PRINT)) ?>
Asset ID: = htmlspecialchars($assetId) ?>
Type: = htmlspecialchars($asset['data_type'] ?? 'N/A') ?>
MIME Type: = htmlspecialchars($asset['mime_type'] ?? 'N/A') ?>
File Size: = number_format($asset['file_size']) ?> bytes
Parent Folder(s):
= htmlspecialchars($folderId) ?>
📂 View Folder
= htmlspecialchars(json_encode($assetResults['direct_asset'], JSON_PRETTY_PRINT)) ?>
Found = count($assets) ?> asset(s) | 🔄 Refresh
✅ CORRECT Asset ID: = htmlspecialchars($asset['asset_id']) ?>
Type: = htmlspecialchars($asset['data_type'] ?? 'N/A') ?>
MIME Type: = htmlspecialchars($asset['mime_type'] ?? 'N/A') ?>
File Size: = number_format($asset['file_size']) ?> bytes
Test Download This Asset 🗑️ Delete= htmlspecialchars(json_encode($assetResults, JSON_PRETTY_PRINT)) ?>