69 lines
1.7 KiB
PHP
69 lines
1.7 KiB
PHP
<?php
|
|
// Set your API key and data center
|
|
$apiToken = 'GZjoFiLmb2j62s8AHmMWKN25BZjGBhsU5ez4cwjn';
|
|
$dataCenter = 'fra1'; // Your data center, e.g., 'fra1'
|
|
|
|
// Set the endpoint URL
|
|
$baseUrl = "https://$dataCenter.qualtrics.com/API/v3/surveys";
|
|
|
|
// Initialize cURL session
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $baseUrl);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
"X-API-TOKEN: $apiToken",
|
|
"Content-Type: application/json"
|
|
]);
|
|
|
|
// Execute the request
|
|
$response = curl_exec($ch);
|
|
|
|
// Check for cURL errors
|
|
if(curl_errno($ch)){
|
|
die('Request Error: ' . curl_error($ch));
|
|
}
|
|
|
|
curl_close($ch);
|
|
|
|
// Decode the response
|
|
$result = json_decode($response, true);
|
|
$surveys = $result['result']['elements'] ?? [];
|
|
|
|
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Select a Qualtrics Survey</title>
|
|
</head>
|
|
<body>
|
|
<h1>Select a Survey</h1>
|
|
|
|
<?php if (empty($surveys)): ?>
|
|
<p>No surveys found or an error occurred.</p><br><br><hr><br>
|
|
|
|
<pre><?php echo print_r($result); ?></pre>
|
|
<pre><?php
|
|
|
|
|
|
?></pre>
|
|
<?php else: ?>
|
|
<form method="POST" action="getData.php">
|
|
<label for="survey_id">Choose a survey to download data and produce reports:</label>
|
|
<select name="survey_id" id="survey_id">
|
|
<?php foreach ($surveys as $survey): ?>
|
|
<option value="<?= htmlspecialchars($survey['id']) ?>">
|
|
<?= htmlspecialchars($survey['name']) ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<br><br>
|
|
<input type="submit" value="Submit">
|
|
</form>
|
|
<?php endif; ?>
|
|
</body>
|
|
</html>
|
|
|
|
|