K
K
ksandr_maykop2017-03-23 21:28:57
PHP
ksandr_maykop, 2017-03-23 21:28:57

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>

I'm actually creating the query like this:
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 );
}

The XML is copied from the example, it shouldn't contain any errors. I'll never know what's wrong and what the server doesn't like about this request.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrKMV34, 2017-03-23
@MrKMV34

Are you sending the request to a sandbox or a production api? Domain name must match both ReportDefinition and CURLOPT_URL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question