-2

I am trying to get output of this API using php. It's a Australia Post Freight calculator. I am not sure what is wrong with it, can some one please suggest. It will be really helpful.

// Set your API key: remember to change this to your live API key in production
$apiKey = API_KEY;

// Set the URL for the Domestic Parcel Size service
$urlPrefix = URL_PREFIX;
$parcelTypesURL = 'https://' . $urlPrefix . '/postage/parcel/domestic/size.json';

// Lookup domestic parcel types (different kinds of standard boxes etc)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $parcelTypesURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('AUTH-KEY: ' . $apiKey));
$rawBody = curl_exec($ch);

// Check the response: if the body is empty then an error occurred
if(!$rawBody){
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}

// All good, lets parse the response into a JSON object
$parcelTypesJSON = json_decode($rawBody);
styl3r
  • 501
  • 7
  • 22
ovic
  • 3
  • 1
  • If that is your API key, you should hide it. Is this code bringing up any errors? – Luke Oct 03 '17 at 03:31
  • That code works. a `print_r($ParcelTypesJSON)` shows the data I would expect. If there is an error, it is outside that code. – Luke Oct 03 '17 at 03:33
  • WARNING curl_init() has been disabled for security reasons on line number 9 This is one of the warning, and this key is the testing one that is why did not hide it – ovic Oct 03 '17 at 03:33
  • 1
    Then your issue is not the code, it is that `curl_init()` has been disabled for security reasons. These warnings are usually there to give you information regarding errors. When asking for help, if you have an error, document the error. – Luke Oct 03 '17 at 03:38

1 Answers1

1

curl_init() is disabled for security reasons...

This means that the server has disabled that function.
If you have control of the server, then enable curl_init() in the php.ini. More information here.
If you do not, try using file_get_contents(). more information here

Luke
  • 639
  • 3
  • 10
  • 1
    or - if your host wont give you curl and and you need curl, move hosts –  Oct 03 '17 at 03:54