Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Need help understanding basics of XML-API for PHP

Discussion in 'cPanel Developers' started by marcelg, Oct 9, 2012.

  1. marcelg

    marcelg Member

    Nov 8, 2007
    Likes Received:
    Trophy Points:

    I have spent lots of time with this and think it's time to ask for some advice.

    I have downloaded the xmlapi.php file and have it included in my scrpt.

    My script specifies the server IP and authenticates via the $xmlapi->hash_auth fine.

    I am just trying to run one command to list accounts: print $xmlapi->listaccts();

    This gives me a blank screen and when I "View Source" I see lots of blank lines. If I comment out the print $xmlapi->listaccts() the blank lines don't appear in the source.

    I checked my error_log with $xmlapi->set_debug(1) and found lots of data going in there.

    error_log shows my Authorization Header followed by any entry starting with RESPONSE: \n <listaccts>\n and it goes on to output all the information I'm trying to get.

    How do I access this information and have it display on my HTML page instead of the error log? I'm guessing I'm missing something here. Please give me some advice.
  2. cPanelDavidN

    cPanelDavidN Integration Developer

    Dec 17, 2009
    Likes Received:
    Trophy Points:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    listaccts(), which calls xmlapi_query() internally, returns a data structure (unless you specify 'json' in a prior invocation of set_output())

    PHP data structures, like arrays and objects, should not be provided as an argument to the print directive. If you know that you have an array, you can use print_r(). If you're want to get an idea of what a variable is or what it contains, you're better served by using var_dump() to simply dump the variable; var_dump() will provide additional markup so that you can understand the internal structure and value of the variable's contents.

    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice