Good afternoon, tell me please, there is a key of Yandex.services, judging by the documentation, the list of banks is given by the following request:

http://api.uslugi.yandex.ru/1.0/banks ? [key=<API-ключ>] & region=<регион> 

Here is my code:

 <?php ini_set('display_errors', 1); error_reporting(E_ALL); $xml = simplexml_load_file("http://api.uslugi.yandex.ru/1.0/banks?[key=***]&region=Moscow"); ?> 

Returns the following:

 Warning: simplexml_load_file( http://api.uslugi.yandex.ru/1.0/banks?%5Bkey=***%5D®ion=Moscow): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in /var/www/neoflat/data/www/neoflatru/calc.php on line 5 Warning: simplexml_load_file(): I/O warning : failed to load external entity "http://api.uslugi.yandex.ru/1.0/banks?%5Bkey=***%5D®ion=Moscow" in /var/www/neoflat/data/www/neoflatru/calc.php on line 5 

Error 401 judging by the documentation authorization error.

What am I doing wrong, who will tell?

Do not kick much, the first time I come across an API.

  • @Negatiff Try to open this address in the browser - cas

2 answers 2

 $query_data = array( 'key' => 'API-ключ для доступа к сервисам', 'region' => 'Moscow' ); //корректно сформированный запрос $query = http_build_query($query_data, '', '&amp;'); //url, на который будет отправляться запрос $service_url = 'http://api.uslugi.yandex.ru/1.0/banks'; //корректно сформированный url вместе с запросом $url = $service_url . '?' . $query; //Домен, на который вы регестрировали API-ключ //Вы указывали его в письме яндексу с запросом ключа $referer = 'URL, для которого действителен указанный API-ключ'; //Отправляем запрос $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, $referer); $content = trim(curl_exec($ch)); curl_close($ch); $xml = simplexml_load_string($content); 
  • Thank you so much! The only thing that gave an error 400 (missing required parameter), after replacing '& amp;' on '&' everything worked fine! Thanks again! - Negatiff

"http://api.uslugi.yandex.ru/1.0/banks?[key=***[®ion=Moscow"

without square brackets. usually square brackets indicate optional parameters

  • It doesn’t matter, it doesn’t work anyway, in the support of Yandex services they said to specify the header: HTTP Referer header with the correct URL for which the specified API key is valid; But I do not quite understand what should be there and how it looks, will you tell me? - Negatiff