Suspending user gives error

B3rt

Verified User
Joined
Oct 12, 2007
Messages
81
If I follow the manual when suspending a user i get an error.

I user the following code to suspend a user:
Code:
/CMD_API_SELECT_USERS?suspend=Suspend&select0=USERNAME&location=CMD_SELECT_USERS

If get the following error:
Code:
Array ( [error] => 1 [text] => Unkown Select Command [details] => none )

I also tried the following code and this also returns an error:
Code:
/CMD_API_SELECT_USERS?dosuspend=yes&select0=USERNAME

USERNAME is ofcourse the correct username of the user on this server.

Could someone please explain to me what i do wrong here, the manual is not very clear in this, maybe the manual could include for each option an example how to implement this.
 
I use POST to do the request

The link you post i used to create the string i used, the instructions are not very clear how to use it.
As I said it would be much clearer if an example was posted on each api command how to use it.
 
Last edited:
Allready tried:
Code:
Array ( [error] => 1 [text] => Cannot Execute Command [details] => Empty post )

This is the error what returns

output on server:
Code:
Debug mode. Level 2000

DirectAdmin 1.37.0
Accepting Connections on port 2222
Sockets::handshake - begin
Sockets::handshake - end
/CMD_API_SELECT_USERS
GET string: select0=apitest&dosuspend=1
 0: Accept: */*
 1: Authorization: Basic
 2: Connection: Close
 3: Host: ssl://xx.xx.xx.xx:2222
 4: User-Agent: HTTPSocket/2.6
Command::doCommand(/CMD_API_SELECT_USERS)
Command::doCommand(/CMD_API_SELECT_USERS) : finished
Command::run: finished /CMD_API_SELECT_USERS

With POST:

Code:
Array ( [error] => 1 [text] => Unkown Select Command [details] => none )

dbug output:
Code:
/CMD_API_SELECT_USERS
GET string: select0=apitest&dosuspend=1
 0: Accept: */*
 1: Authorization: Basic
 2: Connection: Close
 3: Content-length: 0
 4: Content-type: application/x-www-form-urlencoded
 5: Host: ssl://xx.xx.xx.xx:2222
 6: User-Agent: HTTPSocket/2.6
Command::doCommand(/CMD_API_SELECT_USERS)
Command::doCommand(/CMD_API_SELECT_USERS) : finished
Command::run: finished /CMD_API_SELECT_USERS
 
Last edited:
I do use POST.

When i use the add user option (also only works with post) it works perfectly.
When i use the suspend option it does not work.
 
I use the PHP API interface /code listed in the knowledge base.
The code used is as already posted in this topic.

There is no error in the PHP code itself, the error occurs in the API itself.

As explained, if i use CMD_SELECT_USERS instead of CMD_API_SELECT_USERS the same PHP code works, the domain is suspended but i do not get an array back with the result as you get in _API_

The fault is not within the PHP code, but if you would like to test download then see:
http://www.directadmin.com/forum/showthread.php?threadid=258

This API PHP class is used to suspend.
 
In your Post#5 I see only GET query, not POST request. Do I miss anything?

I know about that code listed in the knowledge base. I wanted to see the exactly yours 2-3 lines, how you do it. If it's top secret, so let it be. I've posted above a 100% example of a request. That's working.
 
In your Post#5 I see only GET query, not POST request. Do I miss anything?

I know about that code listed in the knowledge base. I wanted to see the exactly yours 2-3 lines, how you do it. If it's top secret, so let it be. I've posted above a 100% example of a request. That's working.

I do not see anu code of you exept the question to try a specific line.


Het is the exact code:
Code:
   include_once('daapi.php');
   $sock = new HTTPSocket;
   $sock->connect("ssl://".$serverip,$bport);
   $sock->set_login($buser,$bpass); 
   $sock->set_method('POST');
   $sock->query('/CMD_API_SELECT_USERS?select0='.$username.'&dosuspend=1');
   $result = $sock->fetch_parsed_body();
   print_r($result);

Ofcourse are the $ values retrieved elsewhere from the script and they are correct, serverip, username etc are 100% correct.
 
Will you try this:

Code:
   include_once('daapi.php');
   $sock = new HTTPSocket;
   $sock->connect("ssl://".$serverip,$bport);
   $sock->set_login($buser,$bpass); 
   $sock->set_method('POST');
   $sock->query('/CMD_API_SELECT_USERS', 
      array(
      'select0' => $username,
      'dosuspend' => 1 
   ));
   $result = $sock->fetch_parsed_body();
   print_r($result);

P.S. The code from the billing won't help you anyway, it does not use httpsocket.php
 
Hello,

As zEitEr mentioned, you can be making a request using POST, but unless you pass the data in the "post" part of the request, it will be "GET" data. Basically, if your data is in the same string as the /CMD?data, that's GET data. The POST data comes after all of the headers.. Using zEitEr's method should do the trick.

For API debugging, you were on the right track, however I would add that it would be helpful to also run the command you want with a browser. It will show you (either get or post) what exactly the send data should look like. Then you'd need only to adjust your script so that it looks the same. Note that CMD_SOMETHING and CMD_API_SOMETHING commands are going to be exactly the same. The only difference is the output generated. The data sent to either would be the same.

Related: http://help.directadmin.com/item.php?id=293

John
 
doesn't work

That still doesn't work. Code is clear from bugs. I use cURL and only that method don't work, I get {"error":"1","text":"Unkown Select Command","details":"none"} (JSON format of message)

I am Zend PHP5 Ceryficated Engineer. Some bug is on Your side
 
"Unkown Select Command"

Im suprised DA didnt change this miss-spelling yet.
 
As I wrote, my code is fine. I use cURL with connect. Some from API functions work fine, but some return me stupid errors like that or when I try get for example List Virtual POP Account I'll get error: "You do not own that domain". Why if I login as admin?
 
Was the domain created by "admin"?
For email accounts, you must be logged in as the user who owns the domain.

Eg, if admin created fred, and fred owns domain.com, then to manage email accounts, your script must be logged in as "fred".

There are 2 ways to login as fred (the end-User).

1) Either use the username "fred" and that account's password, eg
Code:
$username = "fred";
$pass = "fredspass";
2) Or use the login-as method with the admin password:
Code:
$username = "admin|fred";
$pass = "adminpass";

Either one will log you in as "fred", then you can manage domain.com (owned by fred)

John
 
Back
Top