SOLVED Manage Json Result from API

diracuser

Active Member
Oct 22, 2014
41
1
8
cPanel Access Level
Root Administrator
Hi
I'm making a script to generate email accounts.
I want to manage the json result, but all the time it returns NULL when I access to the fields "reason" and "result"
This is my var_dump result from API:
Code:
vstring(232) {"cpanelresult":{"error":"The account [email protected] already exists!","func":"addpop","data":[{"reason":"The account [email protected] already exists!","result":0}],"apiversion":2,"module":"Email","event":{"result":1}}}
and this is my access to the fields that return NULL:
Code:
var_dump ($resultado['cpanelresult']['data'][0]['reason']);
var_dump ($resultado['cpanelresult']['data'][0]['result']);
How can I access?
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463

diracuser

Active Member
Oct 22, 2014
41
1
8
cPanel Access Level
Root Administrator
Thanks for your response.

But I have the same problem.

This is my script:


Code:
<?
require_once "/usr/local/cpanel/php/cpanel.php";
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.

// Call the function.
$my_variable = $cpanel->uapi(
    'Email', 'add_pop',
    array(
        'email'           => 'xxxxx',
        'password'        => 'xxxx',
        'quota'           => '1024',
        'domain'          => 'xxx.xx',
        'skip_update_db'  => '1',
        )
);


var_dump (json_encode($my_variable));
$resultado = json_encode($my_variable);
var_dump($resultado[cpanelresult][result][errors]);
echo($resultado[cpanelresult][result][errors]);

 ?>
And this is the output:


var_dump:
Code:
string(192) "{"cpanelresult":{"func":"add_pop","apiversion":3,"result":{"status":0,"data":null,"messages":null,"metadata":[],"errors":["The account [email protected] already exists!"]},"module":"Email"}}"

var_dump and for the field func:
string(1) "{" 
{

echo returns: 
{
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463

diracuser

Active Member
Oct 22, 2014
41
1
8
cPanel Access Level
Root Administrator
My API works fine, because :

string(192) "{"cpanelresult":{"func":"add_pop","apiversion":3,"result":{"status":0,"data":null,"messages":null,"metadata":[],"errors":["The account [email protected] already exists!"]},"module":"Email"}}"

Is the api result, and the API tells that the account already exist .It's ok because in my test this account exists....

I resolve doing this:

$resulCpanel =$cpanel->get_result();
$resull0 = $resulCpanel[0]['result'];
$resul1 = $resulCpanel[0]['reason'];




Thanks
 
  • Like
Reactions: cPanelMichael