[ 'asset' => [ 'metadata' => [ 'metadata_element_list' => [ [ 'id' => 'FERRERO.FIELD.MKTG.ASSET TYPE', 'type' => 'com.artesia.metadata.MetadataField', 'value' => [ 'cascading_domain_value' => false, 'domain_value' => true, 'value' => [ 'type' => 'string', 'value' => 'heroimage' ] ] ], [ 'id' => 'FERRERO.FIELD.FISCAL YEAR', 'type' => 'com.artesia.metadata.MetadataField', 'value' => [ 'cascading_domain_value' => false, 'domain_value' => true, 'value' => [ 'type' => 'string', 'value' => '2025/2026' ] ] ], [ 'id' => 'MAIN_LANGUAGES', 'parent_table_id' => 'FERRERO.TABULAR.FIELD.MAIN LANGUAGES', 'type' => 'com.artesia.metadata.MetadataTableField', 'values' => [ [ 'cascading_domain_value' => false, 'domain_value' => true, 'value' => [ 'field_value' => [ 'type' => 'string', 'value' => 'IT' ], 'type' => 'com.artesia.metadata.DomainValue' ] ] ] ], [ 'id' => 'ARTESIA.FIELD.ASSET NAME', 'type' => 'com.artesia.metadata.MetadataField', 'value' => [ 'cascading_domain_value' => false, 'domain_value' => true, 'value' => [ 'type' => 'string', 'value' => 'test_upload.jpg' ] ] ], [ 'id' => 'FERRERO.FIELD.STATE', 'type' => 'com.artesia.metadata.MetadataField', 'value' => [ 'cascading_domain_value' => false, 'domain_value' => true, 'value' => [ 'type' => 'string', 'value' => 'Local' ] ] ] ] ], 'metadata_model_id' => 'ECOMMERCE', 'security_policy_list' => [ ['id' => 1594] ] ] ] ]); $manifest = json_encode([ 'upload_manifest' => [ 'master_files' => [ [ 'file' => [ 'file_name' => 'test_upload.jpg', 'file_type' => 'image/jpeg' ] ] ] ] ]); $folderId = 'e96080ba0cd1427d253a28a87504b6665eaa02cb'; // Prepare multipart data $postFields = [ 'asset_representation' => $assetRepresentation, 'parent_folder_id' => $folderId, 'manifest' => $manifest, 'files' => new CURLFile($testFile, 'image/jpeg', 'test_upload.jpg') ]; echo "Upload URL: https://ppr.dam.ferrero.com/otmmapi/v6/assets\n"; echo "Folder ID: $folderId\n"; echo "Asset Representation size: " . strlen($assetRepresentation) . " bytes\n"; echo "Manifest size: " . strlen($manifest) . " bytes\n\n"; // Upload $ch = curl_init(); $cookieFile = sys_get_temp_dir() . '/ferrero_test_cookies.txt'; curl_setopt_array($ch, [ CURLOPT_URL => 'https://ppr.dam.ferrero.com/otmmapi/v6/assets', CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields, CURLOPT_HTTPHEADER => [ 'Accept: application/json', 'Authorization: Bearer ' . $accessToken ], CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT => 60, CURLOPT_COOKIEJAR => $cookieFile, CURLOPT_COOKIEFILE => $cookieFile, CURLOPT_HEADER => true, CURLOPT_VERBOSE => true ]); echo "Executing upload...\n"; $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $curlError = curl_error($ch); curl_close($ch); echo "\n=== RESPONSE ===\n"; echo "HTTP Code: $httpCode\n"; if ($curlError) { echo "cURL Error: $curlError\n"; } $headers = substr($response, 0, $headerSize); $body = substr($response, $headerSize); echo "\nResponse Headers:\n"; echo $headers . "\n"; echo "\nResponse Body:\n"; echo $body . "\n"; if ($httpCode == 201 || $httpCode == 202) { echo "\n✅ SUCCESS! Upload accepted!\n"; $responseData = json_decode($body, true); if (isset($responseData['asset_resource_list'])) { echo "Asset ID: " . ($responseData['asset_resource_list']['asset_resource'][0]['asset']['asset_id'] ?? 'N/A') . "\n"; } } else { echo "\n❌ FAILED with HTTP $httpCode\n"; $responseData = json_decode($body, true); if (isset($responseData['exception_body'])) { echo "Error: " . $responseData['exception_body']['message'] . "\n"; echo "Debug: " . $responseData['exception_body']['debug_message'] . "\n"; } } echo "\nDone.\n";