<?php
//$url = 'localhost/api/avanws.php';
$url = 'http://test.papelcero.es/api/avanws.php';
$data = array (
    "grant_type" => "client_credentials",
    "client_secret" => "9b87f76e-def1-4515-9a62-fcefb6a133797",
    "client_id" => "API-ADESSO_dev",
    "service" => "servToken",
    "code" => "8356e8922cdccb82gh538fu2"
);
$headers = [];
$result = curlPost($url,$data,$headers);
print_r($result);
//=====================================================================
$headers = array(
    'authorization-token: Bearer ' . $result->servToken->client_token,
    'client-id: API-ADESSO_dev',
    'p0-api-key: 9383juhs9337bcla64l9hbs87a' 
);
$data = array(
    "service" => "servUpdateContact",
    "contact_nif" => "A989898",
    "contact_group" => "1",
    "contact_type" => "CONTACTO",
    "contact_name" => "CONTACTO",
    "contact_lastname" => "PRUEBA ADESO",
    "contact_lastname2" => "API",
    "contact_direction" => "CALLE UNO",
    "contact_phone" => "2423905",
    "contact_email" => "prueba@asdf.com",
    "contact_direction_org" => "Calle uni"
);
$result = curlPost($url,$data,$headers);
print_r($result);
//=====================================================================
function curlPost($url,$data,$headers) {
    $ch = curl_init();
    $timeout = 30;
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $response = curl_exec ($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    return json_decode($response);
}
?>