Answer the question
In order to leave comments, you need to log in
Why is the response from the Yandex Direct server erroneous (API, statistics, v5, sandbox)?
I'm trying to send an API request to Yandex Direct (sandbox) to get campaign statistics. I get a response:
<reports:reportdownloaderror xmlns:reports="http://api.direct.yandex.com/v5/reports">
<reports:apierror>
<reports:requestid>6057797371104602549</reports:requestid>
<reports:errorcode>1002</reports:errorcode>
<reports:errormessage>Ошибка операции</reports:errormessage></reports:apierror>
</reports:reportdownloaderror>
function QueryToYandex( $service, $data ) {
$tokenYandex = "........";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api-sandbox.direct.yandex.com/v5/".$service,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
//CURLOPT_ENCODING => "",
//CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
//CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"accept-language: ru",
"authorization: Bearer ".$tokenYandex,
"Client-Login: .....",
"processingMode: online",
"returnMoneyInMicros: false",
"Content-Type: text/xml"
),
)
);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($curl);
if(!$res){
$error = curl_error($curl).'('.curl_errno($curl).')';
$res = $error;
}
else
curl_close($curl);
return $res;
}
function custom_report( $IdCampaign , $DateRange ) {
$service = "reports";
$data ='<?xml version="1.0" encoding="UTF-8"?>
<ReportDefinition xmlns="http://api.direct.yandex.com/v5/reports">
<SelectionCriteria>
<Filter>
<Field>CampaignId</Field>
<Operator>EQUALS</Operator>
<Values>191853</Values>
</Filter>
</SelectionCriteria>
<FieldNames>Date</FieldNames>
<FieldNames>Clicks</FieldNames>
<FieldNames>Cost</FieldNames>
<FieldNames>AdNetworkType</FieldNames>
<OrderBy>
<Field>Date</Field>
</OrderBy>
<ReportName>Campaign #191853</ReportName>
<ReportType>CUSTOM_REPORT</ReportType>
<DateRangeType>THIS_MONTH</DateRangeType>
<Format>TSV</Format>
<IncludeVAT>NO</IncludeVAT>
<IncludeDiscount>NO</IncludeDiscount>
</ReportDefinition>';
return QueryToYandex( $service, $data );
}
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