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:

Code Block
languagephp
<?php
$json = array("portal" => "DKWWFCOPEN",
              "username" => "MYUSERNAME",
              "password" => "MYPASSWORD",
              "apikey" => "", // empty for now
              "commands" => array(array("command" => "GetPriceCalculation",
                                        "from_country" => 23,
                                        "from_location" => 1,
                                        "to_country" => 23,
                                        "to_location" => 2,
                                        // each package must be described by fields pcsN,packtypeN,weightN,volumeN,widthN,heightN,lengthN
                                        // N is from 1 and up
                                        "pcs1" => 1,
                                        "packtype1" => 23,
                                        "weight1" => 100,
                                        "volume1"  => 0.5*0.5*0.1,
                                        "width1" => 50, "height1" => 50, "length1" => 10,

                                        "pcs2" => 1,
                                        "packtype2" => 23,
                                        "weight2" => 100,
                                        "volume2" => 0.5*0.5*0.1,
                                        "width2" => 50, "height2" => 50, "length2" => 10,
                                       )
                                 )
           );

$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']);
$c = $d['results'][0];
if ($c['status'] != 1)   exit('GetPriceCalculation failed: '.$c['msg']);
$sheets = $c['sheets'];  // the result for each price sheet
foreach ($sheets as $sheet) {
    // the result for a price sheet includes title,currency,total cost,addon,transittime,note and lines
    // each line describes a fee or other cost
    
    echo "\n";
    echo "Title: ".$sheet['title']."\n";
    echo "Currency: ".$sheet['currency']."\n";
    echo "Total cost: ".$sheet['total_excl']."\n";
}
?>

...