Answer the question
In order to leave comments, you need to log in
CURL POST Yandex api?
Need help, first time doing post requests and just started learning cURL. Executing request 1) below, in response I get - ({"message":"request must be in json format"}).
Executing the request 2) I get -{"message":"json root must be an object"}
What could be the problem?
one)
$tt= $curl->post('https://fleet-api.taxi.yandex.net/v1/parks/driver-profiles/list',array(
'X-Client ID:'=>'taxi/park/<token>',
'X-API-key:' => '<api key>',
'Accept-Language:'=>'en',
));
sendMessage($uid,$tt);
2)$tt= $curl->post('https://fleet-api.taxi.yandex.net/v1/parks/driver-profiles/list',array(
'{"X-Client ID":"taxi/park/<id>,"X-API-key"<api key>", "Accept-Language":"en"}',
));
Answer the question
In order to leave comments, you need to log in
You must indicate in the header the type of response to be received. This example should help you understand what is wrong and where to fix it:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fleet-api.taxi.yandex.net/v1/parks/driver-profiles/list",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>"{\n \"limit\": 100,\n \"offset\": 0,\n \"query\": {\n \"park\": {\n \"id\": \"ee6f33c4562b4e1f8646d157bd70b2c4\",\n \"driver_profile\": {\n }\n }\n },\n \"fields\": {\n },\n \"sort_order\": [{\n \"direction\": \"asc\",\n \"field\": \"account.current.balance\"\n }]\n}",
CURLOPT_HTTPHEADER => array(
"Accept: application/json",
"Content-Type: application/json",
"X-Client-ID: API7-sandbox-client",
"X-API-Key: FoquKQFW/WgvS/Kae/GheB/BdOtcvzSZLYrZv",
"Accept-Language: ru"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question