The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get results data from json using $xmlapi.

Discussion in 'cPanel Developers' started by Krystalogik, Jan 9, 2015.

  1. Krystalogik

    Krystalogik Registered

    Joined:
    Jan 9, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    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($actiontrue);

    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.
     
  2. Krystalogik

    Krystalogik Registered

    Joined:
    Jan 9, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    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']
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,808
    Likes Received:
    667
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page