SSL: no alternative certificate subject name matches target host name

Suddenly getting the following error.

Error: SSL: no alternative certificate subject name matches target host name ‘api.companieshouse.gov.uk

Nothing has changed in my source code and this has been working smoothly for over a year up until last week.

$query = curl_init();
curl_setopt($query, CURLOPT_URL, “https://api.companieshouse.gov.uk/search?q=$search&start_index=0”);
curl_setopt($query, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($query, CURLOPT_CUSTOMREQUEST, “GET”);
curl_setopt($query, CURLOPT_USERPWD, $api_key);
curl_setopt($query, CURLINFO_HEADER_OUT, true);
$result = curl_exec($query);
if (curl_errno($query)) {
echo 'Error: ’ . curl_error($query);
}
curl_close ($query);

$result = json_decode($result, true);

Any input greatly appreciated.

I have narrowed down the issue potentially being CN = companieshouse.gov.uk on the ssl certificate

In case anyone else runs into this issue fault found

It seems that api.companieshouse.gov.uk was resolving to the wrong IP at some point recently, which ended up cached on our server and caused further requests to reach the wrong IP addresses (35.178.126.9 and 35.178.141.196) where the SSL mismatch occurred.

A local DNS flush fixed the issue.

I have passed on your comments to our Network team here for any further information they can supply.