<?php
// Define the API endpoint URLs
$entries_url = ‘https://www.visitestonia.com/api/Entries_v4.xsd’;
$domains_url = ‘https://www.visitestonia.com/api/Domains_v2.xsd’;
// Define the version parameter
$version = ‘1.0’;
// Define the authentication credentials
$username = ‘VisitVirumaaVe’;
$password = ‘yXQSNykX6v’;
// Define the delay between API requests in seconds
$delay = 5;
// Define the function to make API requests
function get_api_response($url, $version, $username, $password) {
// Set up the cURL request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . ‘?version=’ . $version);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/xml’));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username . ‘:’ . $password));
// Make the request
$response = curl_exec($ch);
// Check for errors
$http_status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_status_code >= 400) {
throw new Exception(‘Error ‘ . $http_status_code . ‘: ‘ . curl_error($ch));
}
// Close the cURL session
curl_close($ch);
// Return the API response
return $response;
}
// Make the initial request to the terms of use page to get user consent
$terms_of_use_url = ‘https://www.puhkaeestis.ee/api/use_terms’;
$terms_of_use_response = file_get_contents($terms_of_use_url);
if (strpos($terms_of_use_response, ‘I agree to the terms of use’) === false) {
die(‘Error: Could not get user consent for API usage.’);
}
// Make the first API request for the entries service
$entries_response = get_api_response($entries_url, $version, $username, $password);
// Wait for the specified delay before making the next request
sleep($delay);
// Make the second API request for the domains service
$domains_response = get_api_response($domains_url, $version, $username, $password);
// Process the API responses as needed
// …
?>