How to get results data from json using $xmlapi.

Krystalogik

Registered
Jan 9, 2015
2
0
1
cPanel Access Level
Reseller Owner
Hey guys

I'm not overly familiar with json and having search alot on this and trying out a ton of things without success I figure I would just sign up to the forums and actually ask. I hate looking like a complete amature, but this has me stumped and I can't for some reason figure it out.. Brain farts...

I've completed the create account part of things without problems. this is a snippet of the code for suspending a user. Part of the config for this script is as follows (config does work fine as tested for creating an account)

PHP:
$xmlapi->set_debug(0);
$xmlapi->set_output('json');
The portion of the code for suspending

PHP:
//suspend
$cp_user = "jonJone";
$reason = "non payment";
$action = $xmlapi->suspendacct($cp_user,$reason);
$result = json_decode($action, true);

if($result['metadata']['result'] == 0)
{ 
   // suspension failed
}
else
{
   // suspension successful
}
At the moment I receive suspension failed. But the account is suspended. Any help or pointers where I'm going wrong would be great. Appreciate the time to read and respond in advance.
 

Krystalogik

Registered
Jan 9, 2015
2
0
1
cPanel Access Level
Reseller Owner
OK, so I managed to figure that one out.

What I needed was:

PHP:
        if($result['result'][0]['status'] == 0)
        { 
             echo 'Account activation failed!'; 
        }
        else
        {
	     echo 'Account activation successful.'; 
        }
Now I have a json result for chaning passwords I cant figure out

Result:

PHP:
array(1)
{
	["passwd"]=> array(1)
	{
		[0]=> array(4)
		{
		["statusmsg"]=> string(40) "Password changed for user “USERNAMEâ€." 

		["services"]=> array(4)
		{
			[0]=> array(1)
			{
				["app"]=> string(6) "system"
			}

			[1]=> array(1)
			{
				["app"]=> string(3) "ftp"
			}
			[2]=> array(1)
			{
				["app"]=> string(4) "mail"
			}
			[3]=> array(1)
			{
				["app"]=> string(5) "MySQL"
			}
		}

		["rawout"]=> string(135) "Password for “locpweb†has been changed. Updating FTP passwords for USERNAME FTP password files updated. FTP vhost passwords synced " 
		["status"]=> int(1)
	}
}
Totally lost as to what I need to get the STATUS part of this into a usable variable (like the $result['result'][0]['status'] as in the last one).

- - - Updated - - -

Figured it out:

$result['passwd'][0]['status']
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,228
463
Hello :)

I am happy to see you were able to address the issue. Thank you for updating us with the outcome.