R
R
rizzli2015-06-25 11:27:53
API
rizzli, 2015-06-25 11:27:53

How to access the Yandex Direct API sandbox?

It seems that I do everything as in the manual, but I can not access the sandbox.
1. Registered the application.
2. Got a debug token. The application appeared in the "My applications" list
3. Enabled the sandbox.
Sending a request:

var sandbox = 'https://api-sandbox.direct.yandex.ru/v4/json/';
var postBody = {
    'method': 'GetCampaignsList',
    'locale': 'ru',
    'token': 'token',
};
var options = {
  url: sandbox,
  followAllRedirects: true,
  body: JSON.stringify(postBody),
  'content-type': 'application/json',
};

request.post(options, function(error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  } else {
    console.log('error', error);
  }
});

In response I get: No access. You need to fill out an app access request in the Direct interface and wait for confirmation.
What am I missing or doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
rizzli, 2015-06-25
@rizzli

In the end, everything worked) Apparently, although they accepted the application for access, in fact, access was received later.

V
Vitaly Sivkov, 2015-06-25
@Sivkoff

As far as I remember, when request.postyou need to write data to the form property, and not to the body.
Well, it's JSON.stringifynot needed.
Those. your options variable should look like this:

var options = {
  url: sandbox,
  followAllRedirects: true,
  form: postBody,
  'content-type': 'application/json',
};

B
BRODJAGA_JR, 2015-08-07
@BRODJAGA_JR

I did everything as a topic starter, but the answer still comes: No access. You need to fill out an app access request in the Direct interface and wait for confirmation.
Where to dig gentlemen?
I take an example in PHP and want to get information about the company in the sandbox:

<?php

/*
    Пример программного кода для работы с API сервиса Яндекс.Директ
 
     В примере использован рекомендуемый синтаксис для работы с API сервиса Яндекс.Директ 
         на языке PHP с использованием протокола JSON и авторизацией по токенам.
 
     Обращаем внимание, что все текстовые данные должны быть в кодировке UTF8
 
     Подробнее про получение токена читайте в документации:
         http://api.yandex.ru/direct/
*/

require_once "HTTP/Request.php";

// Важно: данные отправляем POST-методом
$req =& new HTTP_Request("https://api.direct.yandex.ru/v4/json/");
$req->setMethod(HTTP_REQUEST_METHOD_POST);

// Инициализация параметров для авторизации
$data = array(
    token => "**************"
    );

// Параметры для запроса метода GetClientInfo
$data['method'] = "GetClientInfo";
$data['param'] = array("*******");

/*
    Если ваша версия php не поддерживает встроенной функции json_encode/json_decode,
    можно воспользоваться библиотекой: http://pear.php.net/package/Services_JSON
*/ 

//require_once 'Classes/json.php';
//$json = new Services_JSON;
//$json_data = $json->encode($data);

/*
    Если встроенные функции json_encode/json_decode поддерживаются, то программа может выглядеть так:
  */      $json_data = json_encode($data);
        $decoded_result = json_decode($result);



$req->addRawPostData($json_data);

$response = $req->sendRequest();
$errmsg = PEAR::isError($response);

if (! $errmsg) {
     $result = $req->getResponseBody();
    // $decoded_result = $json->decode($result);
      $decoded_result = json_decode($result);

     if (isset($decoded_result->data)) {

         // Обработка ответа метода
         print_r($decoded_result);

     } else if ($decoded_result->error_code) {
         // Если ошибку вернул сервер API
         echo "Error: code = ".$decoded_result->error_code
                     .", str = ".$decoded_result->error_str
                     .", detail = ".$decoded_result->error_detail;
     } else {
         echo "Unknown error";
     }

} else {
    // Если ошибка произошла при попытке запроса
    echo "Request error: ".$errmsg;
}

?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question