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.

Can I get an example of the API?

Discussion in 'cPanel Developers' started by cronik, Mar 30, 2012.

  1. cronik

    cronik Registered

    Joined:
    Jul 30, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I read through the api documents, I'm fairly good with PHP. All though, I'm unsure on when a user enters a, Subdomain, an Email, a Username, a Password, I don't get how you send that information to cPanel and receive a message saying "Yeah! It was created!".

    Can someone give me a PHP example of that? Maybe have a few text boxes in there for example? I'd really apprecaite it!

    Peter
     
  2. cronik

    cronik Registered

    Joined:
    Jul 30, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Anyone???
    too short
     
  3. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
  4. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    if you're a PHP developer and you wanting to invoke cPanel API calls, you should consider using this PHP client class: https://github.com/CpanelInc/xmlapi-php . This is used for remote cPanel & WHM API calls. If you are developing a cPanel plugin, then you will use the LiveAPI for PHP client class (/usr/local/cpanel/php/cpanel.php on you cPanel box).

    There are several threads about both class. If you have any specific question, let us know.

    Regards,
    -DavidN
     
  5. cronik

    cronik Registered

    Joined:
    Jul 30, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Wow! That api really helped. The code I have is:
    All though, it doesn't print anything but it creates the account. I just want to know how I can print out to users saying, "Yes, your account was created"

    EDIT: Even if I do listaccts() it doesn't display anything
     
  6. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    cronik,

    that likely won't work. (I think the examples that ship with xmlapi.php erroneously have that [I'll open a ticket to get that updated]). The default return from those query methods is a SimpleXML object, so, calling 'print' on an object is not meaningfull. You will need to traverse the the object to determine the state of action.

    There are a couple of ways you can go about it.
    1) change the output to 'array' with set_output() prior to the api call, and iterate that response
    2) use the SimpleXML object's method interface (that should map the the nodes of the response)

    In either case, depending on the exact function, you will want to evaluate the status node: "<status>$some_bool</status>". The Remote API function documentation should have examples of the expected output

    Depending on how you have your PHP error settings, and how you PHP is getting executed, set_debug(1) may or may not render a copy of the response; once that is established correctly for your development environment, you can get an idea of what you're traversing. I suggest doing a forum/google search for xmlapi.php and display_errors(): Somewhere I've written a length post or two about that specific topic. (if you can't find it or are still having trouble, let me know)

    Regards,
    -DavidN
     
Loading...

Share This Page