CMD_API_DOMAIN returning empty result on success

kristian

Verified User
Joined
Nov 4, 2005
Messages
440
Location
Norway
In a script, I use CMD_API_DOMAIN to change the selected PHP version for a domain. On most servers, this works fine. However, one some servers, the PHP selection is done, but the result handed back from the API is empty, leaving my script to be somewhat confused as to what happened with the API call.

I ran directadmin in debug mode, and these are the results. The only real difference I can see is the api=0 vs api=1. I don't know what that actually means, but it seems maybe directadmin thinks it wasn't an API call, and that's why it doesn't return anything? Does anyone know what could cause this, and how to fix it?

A server where everything works as normal:
Code:
# ./directadmin version
DirectAdmin v.1.643 3d897a3a089fd226d878f21666efcd2a35fcc3e8

# ./directadmin server "--debug=2000"
[...]
/CMD_API_DOMAIN
 0: Accept-Encoding: gzip
 1: Accept: */*
 2: Authorization: Basic <redacted>
 3: Content-Length: 71
 4: Content-Type: application/x-www-form-urlencoded
 5: Da-Ipc-Signature: <redacted>
 6: Da-Licc-Nresellers: -1
 7: Da-Licc-Nusers: -1
 8: Da-Licc-Vdomains: -1
 9: Host: <redacted>:2222
10: Https: //<redacted>:2222
11: User-Agent: HTTPSocket/3.0.1
12: X-Da-Remote-Ip: <redacted>
13: X-Forwarded-For: <redacted>
Post string: action=php_selector&domain=<redacted>&php1_select=3&php2_select=0
Authentication::creatorValid: got type 3 for user admin:  isDemo=0
auth.authenticated
Plugin::addHooks: start
Plugin::addHooks: end
Command::doCommand(/CMD_API_DOMAIN)
Apache::write_php_fpm_cgi: No domains for User <redacted> are using php 81. Deleting /usr/local/directadmin/data/users/<redacted>/php/php-fpm81.conf to reduce the number of unused pools.
Apache::write_php_fpm_cgi: No domains for User <redacted> are using php 80. Deleting /usr/local/directadmin/data/users/<redacted>/php/php-fpm80.conf to reduce the number of unused pools.
installing crontab (use_template=0 euid=0): /usr/bin/crontab -u <redacted> ./data/users/<redacted>/crontab.conf.tmp 2>&1
#direct_crons enabled. Safe to edit this file. DirectAdmin will update accordingly.
PATH=/usr/local/php74/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/<redacted>/.local/bin:/home/<redacted>/bin


Dynamic(api=1, error=0):
    text='PHP versions saved'
    result='<a href="CMD_ADDITIONAL_DOMAINS?action=view&domain=<redacted>">Back</a>'
Command::doCommand(/CMD_API_DOMAIN) : finished
Command::run: finished /CMD_API_DOMAIN
[...]

## My script receives this array as a result:
Array
(
    [error] => 0
    [text] => PHP versions saved
    [details] => <a href="CMD_ADDITIONAL_DOMAINS?action=view&domain=<redacted>">Back</a>
)

And a server where the result is empty (but PHP version is changed):
Code:
# ./directadmin version
DirectAdmin v.1.643 3d897a3a089fd226d878f21666efcd2a35fcc3e8

# ./directadmin server "--debug=2000"
[...]
/CMD_API_DOMAIN
 0: Accept-Encoding: gzip
 1: Accept: */*
 2: Authorization: Basic <redacted>
 3: Content-Length: 69
 4: Content-Type: application/x-www-form-urlencoded
 5: Da-Ipc-Signature: <redacted>
 6: Da-Licc-Nresellers: -1
 7: Da-Licc-Nusers: -1
 8: Da-Licc-Vdomains: -1
 9: Host: <redacted>:2222
10: Https: //<redacted>:2222
11: User-Agent: HTTPSocket/3.0.1
12: X-Da-Remote-Ip: <redacted>
13: X-Forwarded-For: <redacted>
Post string: action=php_selector&domain=<redacted>&php1_select=3&php2_select=0
Authentication::creatorValid: got type 3 for user admin:  isDemo=0
auth.authenticated
Plugin::addHooks: start
Plugin::addHooks: end
Command::doCommand(/CMD_API_DOMAIN)
Apache::write_php_fpm_cgi: No domains for User <redacted> are using php 81. Deleting /usr/local/directadmin/data/users/<redacted>/php/php-fpm81.conf to reduce the number of unused pools.
Apache::write_php_fpm_cgi: No domains for User <redacted> are using php 80. Deleting /usr/local/directadmin/data/users/<redacted>/php/php-fpm80.conf to reduce the number of unused pools.
installing crontab (use_template=0 euid=0): /usr/bin/crontab -u <redacted> ./data/users/<redacted>/crontab.conf.tmp 2>&1
#direct_crons enabled. Safe to edit this file. DirectAdmin will update accordingly.
MAILTO=""
PATH=/usr/local/php74/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games


Dynamic(api=0, error=0):
    text='PHP versions saved'
    result='<a href="CMD_ADDITIONAL_DOMAINS?action=view&domain=<redacted>">Back</a>'
Command::doCommand(/CMD_API_DOMAIN) : finished
Command::run: finished /CMD_API_DOMAIN
[...]

## My script receives this array as a result:
Array
(
)
 
With json=yes added, I get this result:
Code:
{
        "result": "",
        "success": "PHP versions saved"
}

Slightly better than empty. Checked on another server where the non-json API call works, I get exactly the same result:

Code:
{
        "result": "",
        "success": "PHP versions saved"
}

I would've assumed that result should have a value, but maybe this is just how it is supposed to be?

When provoking an error by passing 5 as value to php1_select, I get this:

Code:
{
        "error": "Error setting PHP versions",
        "result": "php1_select and php2_select must be 0-3\n"
}

So it seems the best way to interpret this is to look for the existence of the key success or error in the json string, and then treat result more as "details".
 
Would you in general recommend to use json=yes for API calls now that I believe support for it has been added to most endpoints?
 
Would you in general recommend to use json=yes for API calls now that I believe support for it has been added to most endpoints?


Yes, I would. It seems it's the only way to get a reliable reply from DirectAdmin now.
 
So it seems the best way to interpret this is to look for the existence of the key success or error in the json string, and then treat result more as "details".

You are right either 'success' or 'error=0'

So, if changing that PHP version does not return a `success` text then it confirms something is wrong (error) even if there is no error code or text given to you.

That is the 'beauty' of Directadmin API.
 
Back
Top