Change User Package with API

marcovoort

Verified User
Joined
May 21, 2014
Messages
5
Hi,

I was searching for a method to modify the package of a user, using the DA API. Unfortunately, the API docs don't seem to reference to anything like this. ( http://www.directadmin.com/api.html#modify )
After some research I found the following thread on this forum: http://forum.directadmin.com/showthread.php?t=43284 . I've implemented this as follows:
PHP:
    $this->obj_socket->query('/CMD_API_MODIFY_USER',
	array(
	'action' => 'package',
	'user' => $s_username,
	'package' => $s_package
    ));
 
    $a_result = $this->obj_socket->fetch_parsed_body();

The $obj_socket is just an instance of the HTTPSocket class provided on the API docs page. However, executing this with proper input (existing user & package), I get the following output:
PHP:
var_dump($a_result);
// -> array(0) { }

i.e., no result at all. In the DA control panel I see the package does not change either, so this code is incorrect. So; I tried changing the value of 'action' to 'modify', 'user' to 'username' and CMD_API_MODIFY_USER to CMD_MODIFY_USER, and some combinations of those, but they did not seem to work either. As I'm quite stuck now, I'd like to ask what I'm doing wrong here?

Thanks in advance!
 
Hello,

At least from here your request seems to be built correct. Make sure you go through authorisation as a reseller successfully prior to the request.

And try to run your request in a browser:

https://<SERVER_IP>:2222/CMD_API_MODIFY_USER?action=package&user=bob&package=light

And here again make sure you go through authorisation as a reseller successfully prior to the request.

Iin the example we change account package for user bob to light.
 
Hi,

Thanks for your answer!

Currently, the requests are all done after identification with the admin user. Does it necessarily have to be the reseller user? Because to me, if a reseller is allowed to make a modification, an admin user should also be allowed to make the same modification? Or isn't that true in this case?
 
If you've got several resellers on a board, then you should use proper credentials of a reseller who created a user account. If you have "admin" as the only admin/reseller account, then it does NOT really matter.

Did you check the link in a browser? What results had you there?

Also you probably want to switch directadmin into a debug mode and try your API requests from your PHP scripts once more time.

If there you still see no responce (i.e. array(0)), then you are probably having an issue with connectivity. Please consider if your Directadmin is running on HTTPS, then in your script you should specify ssl://server_ip:2222/ (not https://). That's important.
 
Quite remarkably, I did not see your reply until now, while I did check this topic every day this week. Well... it must be my browser acting against me :P .

Thanks for you reply; I will investigate your questions and suggestions friday, I hope it will solve the problem.
Our API communicates through the admin-user, and there are no resellers apart from ourselves; so the admin user is the only reseller user in this configuration.

I will reply again friday with my findings :) .
 
Requesting the page manually through the browser seemed to work flawlessly. After some investigation, it seems our implementation missed a connect()-call, which was the cause of all the trouble... (The other calls, like creating a user, did call the connect(), so they did work..)

Anyways, as I could not find any documentation on this in first case, at that moment I thought the problem ought to be with my API-call. I would have never guessed a connect()-call would be the cause..

So; many thanks! Everything works like a charm now :) .
 
Back
Top