$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);
$assetId = $_GET['asset_id'] ?? '001aca62191e54abd8e145d688ce962ee98326cb';
$renditionId = $_GET['rendition_id'] ?? '';
$results = [];
if ($_GET['action'] === 'test') {
$apiClient = new ApiClient();
$apiClient->setBaseUrl($configV3->getBaseUrl());
// Get OAuth2 token
$oauth2Handler = new ReflectionProperty($testRunner, 'oauth2Handler');
$oauth2Handler->setAccessible(true);
$oauth2HandlerInstance = $oauth2Handler->getValue($testRunner);
$authHeader = null;
if ($oauth2HandlerInstance) {
$authHeader = $oauth2HandlerInstance->getAuthHeader();
$apiClient->setHeader('Authorization', $authHeader);
}
// Show auth status
echo "
";
echo "🔑 Authentication Status:
";
echo "OAuth2 Handler: " . ($oauth2HandlerInstance ? 'Active' : 'Not found') . "
";
echo "Auth Header: " . ($authHeader ? substr($authHeader, 0, 20) . '...' : 'Not set') . "
";
echo "Token Info: " . ($oauth2HandlerInstance ? json_encode($oauth2HandlerInstance->getTokenInfo()) : 'N/A');
echo "
";
// Try multiple download endpoints
// Note: V3 Postman collection shows {{baseUrl}}/assets/{id}/contents
// where {{baseUrl}} = https://ppr.dam.ferrero.com/otmmapi
$endpoints = [
// Standard v6 API format (most likely correct based on errors)
'/v6/assets/' . $assetId . '/contents',
'/v6/assets/' . $assetId . '/content',
'/v6/renditions/' . $assetId,
];
// If rendition ID provided, try it
if ($renditionId) {
array_unshift($endpoints, '/v6/renditions/' . $renditionId);
array_unshift($endpoints, '/renditions/' . $renditionId);
}
foreach ($endpoints as $endpoint) {
$request = ['method' => 'GET', 'url' => $endpoint];
$response = $apiClient->executeRequest($request);
$isError = false;
$errorMsg = null;
if ($response['success'] && !empty($response['body'])) {
$jsonCheck = json_decode($response['body'], true);
if ($jsonCheck && isset($jsonCheck['exception_body'])) {
$isError = true;
$errorMsg = $jsonCheck['exception_body']['message'] ?? 'Error';
}
}
$results[] = [
'endpoint' => $endpoint,
'full_url' => $configV3->getBaseUrl() . $endpoint,
'http_code' => $response['http_code'],
'success' => $response['success'],
'body_size' => strlen($response['body'] ?? ''),
'is_error' => $isError,
'error_msg' => $errorMsg,
'is_binary' => !$isError && $response['success'] && strlen($response['body'] ?? '') > 1000
];
// If successful, try to save the file
if (!$isError && $response['success'] && strlen($response['body'] ?? '') > 1000) {
$filename = "test_download_" . basename($endpoint) . ".jpg";
$filepath = "downloads/" . $filename;
if (!is_dir('downloads')) {
mkdir('downloads', 0755, true);
}
file_put_contents($filepath, $response['body']);
$results[count($results) - 1]['saved_to'] = $filepath;
$results[count($results) - 1]['saved_size'] = filesize($filepath);
}
}
}
$oauth2Status = $testRunner->getOAuth2Status();
?>
Direct Download Test
🔍 Direct Download Test
= ($oauth2Status['has_token'] ?? false) ? '✅ OAuth2 Token Active' : '❌ OAuth2 Token Issue' ?>
Download Endpoint Test Results
| Endpoint |
Full URL |
HTTP |
Size |
Status |
Result |
= htmlspecialchars($result['endpoint']) ?> |
= htmlspecialchars($result['full_url']) ?> |
= $result['http_code'] ?> |
= number_format($result['body_size']) ?> bytes |
✅ BINARY FILE
❌ ERROR
⚠️ UNKNOWN
|
Saved to: = htmlspecialchars($result['saved_to']) ?>
(= number_format($result['saved_size']) ?> bytes)
= htmlspecialchars($result['error_msg']) ?>
|
✅ Look for green rows with "BINARY FILE" - those are successful downloads!