To get a list of deputy administrators in the docks, it is indicated that the get method should be sent here.

GET /api2/admin/deputy/list?domain=domain.com HTTP/1.1 Host: pddimp.yandex.ru PddToken: 123456789ABCDEF0000000000000000000000000000000000000 

How can I implement the php method? tried through file_get_contents like this

 print_r(file_get_contents('https://pddimp.yandex.ru/api2/admin/deputy/list?domain=mgtcontrol.ru&Pddtoken=123456')); 

but not coming out

  • Yokarny bogeyman, file_get_contents reads the contents of a file into a string, rather than sending a request. We read xhr or use ajax through jquery or its short methods $.get , $.post , $.load . Or even use the form via html for get request - Mr. Black
  • If you do not know, keep silent. The answer just does come, just swears at auth - Anatoly
  • The answer comes not, and json a file, and through txt. I just know what I'm saying - Mr. Black

2 answers 2

PddToken is not a GET parameter, but a custom header.

Through file_get_contents additional control over HTTP requests can be obtained through the stream mechanism. For example,

 $opts = array( 'http'=>array( 'method'=>"GET", 'header'=>"PddToken: 123456789ABCDEF0000000000000000000000000000000000000" ) ); $context = stream_context_create($opts); $response = file_get_contents('https://pddimp.yandex.ru/api2/admin/deputy/list?domain=mgtcontrol.ru', false, $context); var_dump($response); 

I get a logical answer

 {"domain": "mgtcontrol.ru", "success": "error", "error": "bad_token"} 

This is no longer no_auth , it is a logical answer about the wrong token.

Or, as usual, use curl to interact.

 $ch = curl_init('https://pddimp.yandex.ru/api2/admin/deputy/list?domain=mgtcontrol.ru'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'PddToken: 123456789ABCDEF0000000000000000000000000000000000000' ], ]); $response = curl_exec($ch); var_dump($response); 
  • It worked, now I want not to get a list but to add it. They need a POST method. How to achieve this? I will be very grateful! - Anatoly
  • You need the options CURLOPT_POST => true and CURLOPT_POSTFIELDS => an array of values ​​or a urlencoded string. For streams do not remember. - Minor
  • tried curlom comes just bool (false) - Anatoly

What exactly does not come out?

Your code works and gives me {"domain": "mgtcontrol.ru", "success": "error", "error": "no_auth"}

Perhaps the fact is that on the server this function can be prohibited to open the url :

Для этой функции вы можете использовать URL в качестве имени файла, если была включена опция "fopen wrappers".

It is also possible that you get the answer, but do not understand how to disassemble json? Look then in the direction of json_decode .

In general, if the answer does not fit - then clarify the question.

  • I get the same thing. - Anatoly
  • comes the same answer as you. - Anatoly
  • Formulate the questions more clearly - I have no desire to catch cons for answering poorly asked questions, much less answering them. If the problem is that you get no_auth - then you need to look in the direction of curl, you can log in to the site using get_file_content (see the description of the function parameter context and something like this: stackoverflow.com/questions/14591601/… ), but not as comfortable as curl. - AK