Getting technical difficulties error when calling external API in WordPress
I’m working on integrating an external API service into my WordPress website. I’m trying to pull country information from a third-party API endpoint but running into issues.
When I use the wp_remote_get() function to make the API call, instead of getting the expected data, I keep seeing this error message:
The site is experiencing technical difficulties.
I’ve set up Composer in my local XAMPP environment and added the required dependencies in my composer.json:
{
"require-dev": {
"mashape/unirest-php": "3.*"
}
}
Here’s the code I’m using to make the API request:
$response = wp_remote_get( 'https://world-countries-api.p.rapidapi.com/countries',
array(
'headers' => array(
"X-RapidAPI-Host" => "world-countries-api.p.rapidapi.com",
"X-RapidAPI-Key" => "abc123def456ghi789jkl012mno345pqr678stu901vwx234"
)
));
if( is_wp_error( $response ) ) {
return false;
}
$response_body = wp_remote_retrieve_body( $response );
$countries_data = json_decode( $response_body );
print_r($countries_data);
I’m including the required API headers but something seems to be wrong. Has anyone encountered similar issues when working with external APIs in WordPress? What could be causing this technical error?
The “technical difficulties” error typically indicates a fatal PHP error occurring in your code. Since you are not receiving the API response, it suggests the issue lies within your implementation rather than the external API itself.
To diagnose the problem, enable WordPress debug logging by including the following lines in your wp-config.php:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
This will log errors to /wp-content/debug.log, allowing you to identify the root cause. In my experience, similar issues often arise because the code may execute before WordPress has fully initialized, causing functions like wp_remote_get to be unavailable.
check your error logs in xampp/htdocs/logs first. make sure your RapidAPI key is active with the right subscription for that endpoint. if that’s not it, try adding ‘timeout’ => 30 to your wp_remote_get array - timeouts cause this a lot. I’ve hit similar issues and it’s usually the API key or timeout.
I’ve encountered this exact issue before. The ‘technical difficulties’ message in WordPress often points to SSL certificate problems when trying to connect to external APIs. Since RapidAPI requires SSL connections, WordPress might struggle to verify the certificate correctly.
You can resolve this by adding the ‘sslverify’ parameter to your wp_remote_get function call:
$response = wp_remote_get( 'https://world-countries-api.p.rapidapi.com/countries',
array(
'sslverify' => false,
'headers' => array(
"X-RapidAPI-Host" => "world-countries-api.p.rapidapi.com",
"X-RapidAPI-Key" => "abc123def456ghi789jkl012mno345pqr678stu901vwx234"
)
));
Additionally, confirm that cURL is enabled in your XAMPP installation, as local development environments often come with incomplete SSL certificate bundles that lead to silent failures. Testing your API key in Postman first can also help ensure it’s functioning properly.