<?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-fcefb6a53095",
    "client_id" => "API-ESMDD_dev",
    "service" => "servToken",
    "code" => "8356e8922cdccb82gh538fu2"
);
$headers = [];
$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);
}
//$url = 'localhost/api/avanws.php/getContacts/all/1000016';
$url = 'http://test.papelcero.es/api/avanws.php/getContacts/ASDASDAS123123';
$headers = array(
    'authorization-token: Bearer ' . $result->servToken->client_token,
    'client-id: API-ESMDD_dev',
    'p0-api-key: 6729hlsu74386sn23876j12xh' 
);
$result = curlGetData($url,$headers);
//===================================
//===================================
print_r($result);
function curlGetData($url,$headers) {

    $ch = curl_init();
    $timeout = 30;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPGET,true);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

    $result = curl_exec($ch);
    curl_close($ch);
    return json_decode($result);
}

?>