Test php basic

<?php

// IMX webservice basic call example
// 2019-09-19

$url = 'https://webservice.imxpostal.fr/smc/rpc/';

// Credentials data given by IMX.
$username = "..." # given by IMX
$password = "..." # given by IMX
$account = "..." # given by IMX

$data = array (
    'jsonrpc' => '2.0',
    'method' => 'api.declare_parcel',
    // request identifier. At the customer's convenience, not necessarily unique.
    'id' => '__test__',  
    'params' =>  array (
        $username,
        $password,
        array (
            'account' => $account,
            // Receiver
            'addressee' => array(
                'name' => 'Jean Dupond',
                'company' => "Dupond & Dupont",
                'address1' => "24 rue de l\'Est",
                'adresse2' => "Bâtiment 2, porte B",
                'adress3' => "Allée 4",
                'postcode' => '60240',
                'town' => 'Chaumont-en-Vexin',
                'country' => 'FR',
                'phone' => '',
                'email' => '',
            ),
            // Sender
            'sender' => array(
                'company' => 'Ma petite entreprise',
                'address1' => '10 rue Elie Cartan',
                'postcode' => '75012',
                'town' => 'Paris',
                'country' => 'FR',
            ),
            'parcel_description' => array(
              'weight' => 3.31,
            ),
            'parcel_content' => 
                array (
                  0 => 
                  array (
                    'description' => 'Pomme',
                    'origine' => 'FR',
                    'currency' => 'EUR',
                    'value' => 2.5,
                  ),
                  1 => 
                  array (
                    'description' => 'Poire',
                    'origine' => 'FR',
                    'currency' => 'EUR',
                    'value' => 5,
                  ),
                  2 => 
                  array (
                    'description' => 'Abricot',
                    'origine' => 'FR',
                    'currency' => 'EUR',
                    'value' => 3,
                  ),
                ),
            'version' => 1,
            'options' => array (
                'label' => 'True',
                'label_format' => 'pdf',
                'service' => '1',
            ),
            'reference' => 'TEST_DOC_PHP',
        ),
    ),
);

$opts = stream_context_create(array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/json',
        'content' => json_encode($data)
    )
));
try { 
  $raw_result = file_get_contents($url,false,$opts);
  echo $raw_result;
  $result = json_decode($raw_result);
  $parser_json = $result->{'result'}->{'label'};
  $pdf_content_data = base64_decode($parser_json);
  $pdf = fopen ('test-etiquette-imx.pdf','w');
  fwrite($pdf,$pdf_content_data);
  echo 'Done'; 
} catch (Exception $e) {
  echo $e->getMessage();
}
?>