$company_name,
"company_num"=>$company_num,
"company_bus_ind"=>$company_bus_ind,
"address"=>$address,
"skip"=>$skip,
"max"=>$max,
"searchType"=>$searchType,
"sortBy"=>$sortBy,
"sortDir"=>$sortDir,
"htmlEnc"=>"1"); // "format"=>"json" -- you can do this if you like... or use the "Content-Type" header value...
// Encode everything that will be sent to query string.
$encoded = '';
foreach($testdata as $name => $value){
$encoded .= urlencode($name).'='.urlencode($value).'&';
}
// chop off the last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);
echo '
The query string we are going to send is:
';
echo "". $encoded ."
";
$ch = curl_init();
$url = "https://services.cro.ie/cws/companies?" . $encoded;
// base64_encode email_address:api_key, preceeded with "Basic ".
// Use the exact email address you signed up with, values are case sensitive.
$headers = array( "Authorization: Basic ".base64_encode("test@cro.ie:da093a04-c9d7-46d7-9c83-9c9f8630d5e0"),
"Content-Type: application/json",
"charset: utf-8");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// curl_setopt($ch, CURLOPT_PROXY, 'http://ip of your proxy:8080'); // Proxy if applicable
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 0);
$response = curl_exec($ch);
// Some values from the header if want to take a look...
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$headerOut = curl_getinfo($ch, CURLINFO_HEADER_OUT);
echo $code.''.$headerOut.'
';
// Don't forget to close handle.
curl_close($ch);
echo "Results:
";
// One way of handling json... use your own preferred method.
$results_array = json_decode($response);
// To view the array structure:
// print_r('');
// print_r($results_array);
// print_r('
');
// Please READ THE DOCUMENTATION on the list of fields avaiable:
// ------->>>> https://services.cro.ie/datadict.aspx
foreach($results_array as $Object){
// Let's just show the name, first line of address, and the primary key , i.e. company num + comp business indicator:
$primarykey = $Object->company_num.'/'.$Object->company_bus_ind;
$company_name = $Object->company_name;
$addr1 = $Object->company_addr_1;
$addr2 = $Object->company_addr_2;
print_r ($primarykey.'
'.
$company_name.'
'.$addr1.' '.$addr2.'
' );
print_r ("===========================
");
}
?>