А, вы вынесли в отдельный вопрос)
Вобщем, StaticCall,UserId - обязательные колонки
Заголовки
Content-Type: multipart/form-data; boundary=------------------------boundary
Content-Length: 12345
Тело
--------------------------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--
Пример(для curl все тоже самое)
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);
Для curl типа того
CURLOPT_POSTFIELDS => $data
CURLOPT_HTTPHEADER => array(
"Content-Type: multipart/form-data; boundary=------------------------$boundary",
"Content-Length: " . strlen($data)