Skip to main content

Manage Json Result from API

Comments

4 comments

  • cPanelMichael
    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
  • diracuser
    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
  • cPanelMichael
    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
  • diracuser
    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.