Manage Json Result from API
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:
and this is my access to the fields that return NULL:
How can I access?
vstring(232) {"cpanelresult":{"error":"The account userauto@xxxx.xxx already exists!","func":"addpop","data":[{"reason":"The account xxxo@xx.xxx already exists!","result":0}],"apiversion":2,"module":"Email","event":{"result":1}}}
and this is my access to the fields that return NULL:
var_dump ($resultado['cpanelresult">['data">[0]['reason">);
var_dump ($resultado['cpanelresult">['data">[0]['result">);
How can I access?
-
Hello, I recommend using UAPI whenever possible. Could you let us know if you experience similar results when using the UAPI function to create a new email account? It's documented at: UAPI Functions - Email::add_pop - Software Development Kit - cPanel Documentation Thank you. 0 -
Thanks for your response. But I have the same problem. This is my script: 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:string(192) "{"cpanelresult":{"func":"add_pop","apiversion":3,"result":{"status":0,"data":null,"messages":null,"metadata":[],"errors":["The account xxx@xxxx.xxx already exists!">},"module":"Email"}}" var_dump and for the field func: string(1) "{" { echo returns: {0 -
errors":["The account xxx@xxxx.xxx already exists!">
It looks like the API function is failing because the email account already exists. Can you reproduce the same issue with your script when there's no error message? Here's a useful document regarding return data: UAPI - Return Data - Software Development Kit - cPanel Documentation Thank you.0 -
My API works fine, because : string(192) "{"cpanelresult":{"func":"add_pop","apiversion":3,"result":{"status":0,"data":null,"messages":null,"metadata":[],"errors":["The account xxx@xxxx.xxx 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 0
Please sign in to leave a comment.
Comments
4 comments