$scopes, 'client_id' => $client_id, 'response_type' => 'code', 'access_type' => 'offline', 'redirect_uri' => $redirect_uri, 'prompt' => 'consent' ]); echo "\nStep 2: Authorize the application\n"; echo "--------------------------------\n"; echo "Open this URL in your browser:\n\n"; echo $auth_url . "\n\n"; echo "After authorization, you'll be redirected to:\n"; echo $redirect_uri . "?code=AUTH_CODE\n\n"; echo "Enter the authorization code: "; $auth_code = trim(fgets(STDIN)); // Step 3: Exchange code for tokens echo "\nStep 3: Exchanging code for tokens...\n"; echo "-----------------------------------\n"; $token_url = 'https://accounts.zoho.com/oauth/v2/token'; $token_params = [ 'grant_type' => 'authorization_code', 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $redirect_uri, 'code' => $auth_code ]; $ch = curl_init($token_url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($token_params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($http_code !== 200) { echo "Error: Failed to get tokens (HTTP $http_code)\n"; echo "Response: " . $response . "\n"; exit(1); } $token_data = json_decode($response, true); if (!isset($token_data['access_token']) || !isset($token_data['refresh_token'])) { echo "Error: Invalid token response\n"; echo "Response: " . $response . "\n"; exit(1); } echo "Success! Tokens received.\n\n"; // Step 4: Get Organization ID echo "Step 4: Getting organization ID...\n"; echo "--------------------------------\n"; $org_url = 'https://www.zohoapis.com/crm/v2/org'; $ch = curl_init($org_url); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Zoho-oauthtoken ' . $token_data['access_token'] ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $org_response = curl_exec($ch); $org_data = json_decode($org_response, true); curl_close($ch); $org_id = isset($org_data['org'][0]['id']) ? $org_data['org'][0]['id'] : 'NOT_FOUND'; // Step 5: Generate config file echo "\nStep 5: Generating configuration\n"; echo "-------------------------------\n"; $config_content = "