Battling with PHP cURL project

I have a project that needs to be delivered urgently. It comprises of a cUrl command which is run inside PHP. I have used cURL countless times with success, but this particular project has me absolutely stumped.

Please can someone help.

• I am calling an API which executes implements as a REST-like API.
• It must execute using an HTTP GET method using UTF-8 encoding and URL encoded values.
• For security, the request must be SSL encrypted
• To access the API, it must have a custom header named x-api-key, along with the value of the API key. An example custom header would be x-api-key: y123456ZXVBG9
• The query parameters must always be supplied as a JSON object. It is recommended to url encode this parameter

An example is shown below:
• Request Format:- api.apicompany.xxx/anyTimeInterrogationRequest

Parameters:-
MapMessage={
“MAP”: {
“operationRequestParameters”: { “anyTimeInterrogationRequestParameters”: {
“Identity”: {
“TIP”: {
“address”: “’.$address.’”
}
},
“requestedInfo”: {“LIN” : true,
“IdState”: true,
“CurrentLIN”: true,
"RequestedDorma1n " : "csDomaln ",
“tim”: true,
“MsClassmark”: true,
“MnpRequestedInfo”: true
}
}
}
}
}’);

I have tried the following with no success:
$geturl = ’ api.apicompany.xxx/anyTimeInterrogationRequest’; /// this is proceeded with an https

MapMessage={
“MAP”: {
“operationRequestParameters”: { “anyTimeInterrogationRequestParameters”: {
“Identity”: {
“TIP”: {
“address”: “’.$address.’”
}
},
“requestedInfo”: {“LIN” : true,
“IdState”: true,
“CurrentLIN”: true,
"RequestedDormain " : "csDomaln ",
“tim”: true,
“MsClassmark”: true,
“MnpRequestedInfo”: true
}
}
}
}
}’);

function curlRequest($geturl) {
$headers = array();
$headers[] = ‘Content-Type: application/json’;
// $headers[] = ‘x-api_key: y123456ZXVBG9’;
$headers[] = ‘Authorization: Token y123456ZXVBG9’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $geturl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
if ($response === FALSE) {
die('Curl failed: ’ . curl_error($ch));
}
curl_close($ch);
return $response;
}

Hi Larry_Hurwitz,

Welcome to our forums.

Do you get an error message, or the page dies at preprocessing?