Answer the question
In order to leave comments, you need to log in
Why doesn't the same code work when downloading offline conversions from the Yandex Metrics API?
I ran into an interesting situation when loading offline conversions via the API. The situation is such that the code works on the test and the conversions go to download, but the following arrives on the main domain:
{"errors":[{"error_type":"invalid_uploading","message":"Incorrect data format, error in line number 1"}],"code":400,"message":"Incorrect data format, error in line number 1"}
$yclid_id = filter_input(INPUT_GET, 'yclid');
if($yclid_id != "") {
function getInfoYa($url,$token,$data,$boundary){
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host:api-metrika.yandex.net','Authorization: OAuth '.$token,"Content-Type: multipart/form-data; boundary=------------------------$boundary","Content-Length: " . strlen($data)));
$response = array();
$response['html'] = curl_exec($ch);
$response['err'] = curl_errno($ch);
$response['errmsg'] = curl_error($ch);
$response['header'] = curl_getinfo($ch);
curl_close($ch);
return $response;
}
$token = "мойтокен";
$orders = "Yclid,Target,DateTime".PHP_EOL;
global $yclid_id;
$yaclid=$yclid_id;
$orders .= "".$yaclid.",target,".time()."".PHP_EOL;
$counterId = номер; //id счетчика
$boundary = "7zDUQOAIAE9hEWoV";
$filename = 'data.csv';
$data = "--------------------------$boundary\x0D\x0A";
$data .= "Content-Disposition: form-data; name=\"file\"; filename=\"$filename\"\x0D\x0A";
$data .= "Content-Type: text/csv\x0D\x0A\x0D\x0A";
$data .= $orders . "\x0A\x0D\x0A";
$data .= "--------------------------$boundary--";
$url = "https://api-metrika.yandex.net/management/v1/counter/".$counterId."/offline_conversions/upload?client_id_type=YCLID&oauth_token=".$token;
$yaInfo = getInfoYa($url,$token,$data,$boundary);
$yaInfo = json_decode($yaInfo["response"]["html"],true);
?><pre><?print_r($yaInfo)?></pre><?
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question