$filename = 'data.csv';
$url = "https://api-metrika.yandex.ru/management/v1/counter/39764535/offline_conversions/upload_calls?client_id_type=USER_ID&oauth_token=$oauth_token";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, TRUE);
$args['file'] = new CurlFile($filename, 'text/csv');
curl_setopt($curl, CURLOPT_POSTFIELDS, $args);
$curl_response = curl_exec($curl);
var_dump($curl_response);
{"uploading":{"id":37360378,"source_quantity":6,"line_quantity":6,"client_id_type":"USER_ID","status":"UPLOADED"}}
"Content-Type: multipart/form-data; boundary=------------------------boundary";
--------------------------boundary\r\n;
Content-Disposition: form-data; name="file"; filename="file.csv"\r\n;
Content-Type: text/csv\r\n\r\n;
ДАННЫЕ\r\n\r;
"--------------------------boundary--"
function request($url, $data, $headers){
$opt = array(
'http' => array(
'method' => 'POST',
'content' => $data,
'header' => $headers
)
);
$context = stream_context_create($opt);
$response = @file_get_contents($url, FALSE, $context);
return $response;
}
$oauth_token='xxx';
$boundary = "7zDUQOAIAE9hEWoV";
$filename = 'data.csv';
$calls = "StaticCall,UserId,DateTime,Price,Currency,PhoneNumber,TalkDuration,HoldDuration,CallMissed,Tag,FirstTimeCaller,URL,CallTrackerURL".PHP_EOL;
$calls .= "1,133591247640966458,1481714026,678.90,RUB,+71234567890,136,17,0,,1,https://test.com/,https://test.com/".PHP_EOL;
$calls .= "1,579124169844706072,1481718066,123.45,RUB,+70987654321,17,23,0,,2,https://test.com/,https://test.com/".PHP_EOL;
$calls .= "1,148059425477661429,1481718126,678.90,RUB,+71234509876,72,11,0,,0,https://test.com/,https://test.com/";
$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 .= $calls . "\x0A\x0D\x0A";
$data .= "--------------------------$boundary--";
$headers = array();
$headers[] = "Content-Type: multipart/form-data; boundary=------------------------$boundary";
$headers[] = 'Content-Length: '.strlen($data);
$headers = implode(PHP_EOL, $headers);
$url = "https://api-metrika.yandex.ru/management/v1/counter/39764535/offline_conversions/upload_calls?client_id_type=USER_ID&oauth_token=$oauth_token";
$result = request($url, $data, $headers);
var_dump($result);
{"id":37246729,"source_quantity":3,"line_quantity":3,"client_id_type":"USER_ID","status":"UPLOADED"}}"
User authorization failed: method is unavailable with group authпри вызове с ключом пользователя?
А попробуйте другое интернет-подключение использовать