Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Example of how to retrieve information about countries, packagetypes etc.

Code Block
languagephp
<?php

$json = array("portal" => "DKWWFCOPEN",
              "username" => "MYUSERNAME",
              "password" => "MYPASSWORD",
              "apikey" => "", // empty for now
              "commands" => array(array("command" => "GetCountriesAndLocations"),
                                  array("command" => "GetPackageTypes"),
                                  array("command" => "GetCurrencies"),
                                  array("command" => "GetUnits")
                                 )
             );

$d = file_get_contents("https://portal.ff.geodis.com/api/endpoint.php?json=".json_encode($json));
$d = json_decode($d, true);
if ($d['status'] != 1)   exit('failed: '.$d['msg']);

// check if countries were retrieved
$r = $d['results'][0];
if ($r['status'] != 1)   exit('GetCountriesAndLocations failed: '.$r['msg']);
$fromcountries = $r['from_countries'];
$tocountries = $r['to_countries'];
// $fromcountries and $tocountries both hold a list of arrays, each array defines a country
// $c = array('id' => 21, 'name' => 'Denmark', 'locations' => array(0 => '-- no location'', 1 => 'Copenhagen', 2 => 'Vejle'));

// check if package types were retrieved
$r = $d['results'][1];
if ($r['status'] != 1)   exit('GetPackageTypes failed: '.$r['msg']);
$packtypes = $r['packtypes'];
// $packtypes is an array of package type names indexed by package type numbers, eg. 'Package' is 23, '20' generel purpose container' is 3

// check if currencies types were retrieved
$r = $d['results'][2];
if ($r['status'] != 1)   exit('GetCurrencies failed: '.$r['msg']);
$currencies = $r['currencies'];
// $currencies is an array of currencies, eg 'EUR','USD','DKK' etc

// check if units were retrieved
$r = $d['results'][3];
if ($r['status'] != 1)   exit('GetUnits failed: '.$r['msg']);
$weightunits = $r['units']['weight']; // either 'kg' or 'lb'
$volumeunits = $r['units']['volume']; // either 'm3' or 'ft3'

?>



Example of how to perform a price calculation:

...