Jump to content
CMSTOOLS.org - форум поддержки и развития CMS

Собрать запрос


KirKMS
 Share

Recommended Posts

Честно говоря я немного туплю и не могу разобраться.

Помогите составить запрос к апи через curl

https://fleet.taxi.yandex.ru/api/docs/ref/DriverProfile/DriverProfileList.html

Ответ выводится в формате Json.

И не могу понять как сделать сортировку по номеру

Мой запрос

    $data = array(
        'X-Client-ID'=>$Client,
        'X-API-Key'=>$ApiKey,
        'Accept-Language'=>'ru'
        );
		

$url = 'https://fleet-api.taxi.yandex.net/v1/parks/driver-profiles/list';  
$ch = curl_init($url);
$data_json = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
	var_dump($response);
	echo $response;

 

Link to comment
Share on other sites

Пытаюсь сделать так

//--- Подготовка и выполнение запроса -----------------------------------//
// Установка HTTP-заголовков запроса
$headers = array(
    "X-Client-ID:  $token",                   // OAuth-токен. 
    "X-API-Key: $clientLogin",                     // Логин 
    "Accept-Language: ru",                            // Язык ответных сообщений
    "Content-Type: application/json; charset=utf-8"   // Тип данных и кодировка запроса
);

// Параметры запроса к серверу API
$params = array(
    'fields' => array(
        'car' => (object) array(),      // Критерий отбора. Для получения всех должен быть пустым
        'park' => (object) array(),      // Критерий отбора. Для получения всех должен быть пустым
        'driver_profile' => array('first_name', 'last_name', 'id')  ,         // Названия параметров, которые требуется получить
        'account' => array('id', 'balance', 'balance_limit', 'currency')           // Названия параметров, которые требуется получить
    )
);
// Преобразование входных параметров запроса в формат JSON
$body = json_encode($params, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);

// Инициализация cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($curl, CURLOPT_CAINFO, getcwd().'\CA.pem');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

// Выполнение запроса, получение результата
$result = curl_exec($curl);

echo $result ;

curl_close($curl);

в ОТВЕТ ПРИХОДИТ

 {"message":"query must be present"}

Не пойму где ошибка

Link to comment
Share on other sites

  • KirKMS featured and unfeatured this topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...