K
K
Khurshed Abdujalil2017-01-16 13:21:49
PHP
Khurshed Abdujalil, 2017-01-16 13:21:49

Bulk adding sites to Yandex.Webmaster, 400 error when adding. What's wrong?

$result=YandexApi::postKeys("https://api.webmaster.yandex.net/v3/user/".$yandex_user_id."/hosts/",
      array(
        'host_url'=> 'https://domain.ru'
      ),
      array('Authorization: OAuth '.$yandex_token, 'Content-type: application/json')
    );


function postKeys($url,$peremen,$headers) {
    $post_arr=array();
    foreach ($peremen as $key=>$value) {
      $post_arr[]=$key."=".$value;
    }
    $data=implode('&',$post_arr);

    $handle=curl_init();
    curl_setopt($handle, CURLOPT_URL, $url);
    curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($handle, CURLOPT_POST, true);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
    $response=curl_exec($handle);
    $code=curl_getinfo($handle, CURLINFO_HTTP_CODE);
    return array("code"=>$code,"response"=>$response);
  }

eventually throws an error
Array
(
[code] => 400
[response] => {"error_code":"ENTITY_VALIDATION_ERROR","error_message":"Cannot parse request entity"}
)
What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kirya-dev, 2017-10-01
@kirya-dev

Lost:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestType);
where requestType in ['POST', 'GET', 'DELETE', 'PUT"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question