Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Member
    Join Date
    May 2007
    Posts
    50

    Default Full doc on XML-API?

    Hello all,

    yesterday I made some progress writing my hooks with postwwwacct, but only shortly...

    After creating the account I would like to continue to create a mysql db, using username and pwd of the acount. Shouldn't be a big deal, but documentation (http://www.cpanel.net/plugins/api2/index.html) doesn't shown any function to create mysql database.

    So, David: How is it with your loved XML-API? Is the doc far from beeing complete, or does the XML-way not allow such basic tasks?

  2. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,718
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by mstuebner View Post
    Hello all,

    yesterday I made some progress writing my hooks with postwwwacct, but only shortly...

    After creating the account I would like to continue to create a mysql db, using username and pwd of the acount. Shouldn't be a big deal, but documentation (http://www.cpanel.net/plugins/api2/index.html) doesn't shown any function to create mysql database.

    So, David: How is it with your loved XML-API? Is the doc far from beeing complete, or does the XML-way not allow such basic tasks?
    Don't worry, I'm constantly nagging the documentation folks for better documentation since some of the most useful functions of the APIs remain undocumented.

  3. #3
    Member
    Join Date
    May 2007
    Posts
    50

    Default

    Quote Originally Posted by cPanelDavidG View Post
    Don't worry, I'm constantly nagging the documentation folks for better documentation since some of the most useful functions of the APIs remain undocumented.
    What does that mean in question of shedule? Could you push a complete list of functions and parameters as a list? The resturn data I can read myself until the documentation is there.

    But actually I cannot do anything.

    So does that mean that functions to handle mysql extist? I have an urgent need on how to call them. Can you help out?

  4. #4
    Member
    Join Date
    May 2007
    Posts
    50

    Exclamation

    Let me push this one again...

    I would like to use the XML-API, but how if not documented. Any hint how to get this information out of the given scripts?

  5. #5
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    10,718
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Quote Originally Posted by mstuebner View Post
    Let me push this one again...

    I would like to use the XML-API, but how if not documented. Any hint how to get this information out of the given scripts?
    XML API documentation has been available at http://www.cpanel.net/plugins/xmlapi/index.html for some time now.

  6. #6
    Member
    Join Date
    May 2007
    Posts
    50

    Default

    Quote Originally Posted by cPanelDavidG View Post
    XML API documentation has been available at http://www.cpanel.net/plugins/xmlapi/index.html for some time now.
    Maybe you re-read the thread, including your former post? Or would you pls. show me the function call to create a Mysql db with those functions? Youself agreed to that this information is still missing.

  7. #7
    Member
    Join Date
    Jun 2007
    Posts
    41

    Default

    Quote Originally Posted by mstuebner View Post
    Maybe you re-read the thread, including your former post? Or would you pls. show me the function call to create a Mysql db with those functions? Youself agreed to that this information is still missing.
    it's described in the xml-api doc page.

    you access the function by visiting an url like this :

    http://user:pass@host:2086/xml-api/f...1=&paramerer2=

    you get an xml stream that you can use for example with the file open functions of php.

    Dominique

  8. #8
    Member
    Join Date
    Nov 2004
    Posts
    7

    Default

    I've found the MySQL functions...

    They're actually not on the XMLAPI docs, but in the cPanel API2 docs (http://www.cpanel.net/plugins/api2/index.html)

    But that said, I do not see how to create a db or a user, only how to pull a list of current ones...

  9. #9
    Member
    Join Date
    May 2007
    Posts
    50

    Default

    Quote Originally Posted by webdes03 View Post
    I've found the MySQL functions...

    They're actually not on the XMLAPI docs, but in the cPanel API2 docs (http://www.cpanel.net/plugins/api2/index.html)

    But that said, I do not see how to create a db or a user, only how to pull a list of current ones...
    Thanx for that statement, otherwise I was close to think I would be blind....

  10. #10
    Member TheIdeaMan's Avatar
    Join Date
    Apr 2005
    Posts
    9

    Lightbulb MySQL XML API access info

    This thread has information on where to find API information for yet undocumented functions (like creating databases, db users, and adding privileges).

    Basically, you open the x3 theme and dig through the files. Most of the functions in there are implemented via the XML API 1 scheme.

    To save you some time, here are the few XML requests you need:

    add database user
    Code:
    <cpanelaction>
      <module>Mysql</module>
      <func>adduser</func>
      <apiversion>1</apiversion>
      <args>{database_user}</args>
      <args>{password}</args>
    </cpanelaction>
    add database
    Code:
    <cpanelaction>
      <module>Mysql</module>
      <func>adddb</func>
      <apiversion>1</apiversion>
      <args>{database}</args>
    </cpanelaction>
    grant privileges to user for database
    Code:
    <cpanelaction>
      <module>Mysql</module>
      <func>adduserdb</func>
      <apiversion>1</apiversion>
      <args>{cpanel_user}_{database}</args>
      <args>{cpanel_user}_{database_user}</args>
      <args>ALL</args>
    </cpanelaction>
    Note: The above code presents granting "ALL" privileges on a database. To grant specific privileges, use several <args></args> each containing the specific privilege to add. Privilege options (for MySQL 5) are: ALTER, CREATEROUTINE, CREATETEMPORARYTABLES, CREATE, DELETE, DROP, SELECT, INSERT, UPDATE, REFERENCES, INDEX, LOCKTABLES, ALL
    Hope that helps.

  11. #11
    Member
    Join Date
    Jun 2005
    Posts
    119

    Default

    Hi TheIdeaMan, Great stuffs.

    However would you mind sharing the full code? I know its XML. But How do I call it from server? do I have to pass these XML data to specific function or URL? and how it be look like?

    Thanks in advance

  12. #12
    Member brianoz's Avatar
    Join Date
    Mar 2004
    Location
    Melbourne, Australia
    Posts
    1,093
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    If you're doing this from within postwwwacct, it's probably easier and quicker to do it using the mysql command:

    Code:
    ME=${0##*/}
    fatal() { echo "$ME: $*" 1>&2 ; exit 1 ; }
    # ...
    
    passcode=$(grep pass= /root/.my.cnf)
    eval $passcode
    [ "$pass" = "" ] && fatal abort - no mysql password from /root/.my.cnf
    
    dbpass=$(dd 2>/dev/null if=/dev/random count=2 | od -d |head -1 | sed -e s/^........// -e 's/ //g' | cut -c1-8)
    [ "$dbpass" = "" ] && fatal could not work out a password
    
    DB=${USER}_sope1
    
    mysql -u root -p$pass <<!
    create database ${DB};
    grant all privileges on ${DB}.* to ${DB}@localhost
    identified by '$dbpass' with grant option;
    !
    The "$dbpass" variable contains the database password used, which should for security's sake NOT be the same as the cpanel password.

    The "$DB" variable is the database name used, which must be prefixed by the username. "$USER" is the username of the target user and can be set from cp_user.

    This is a fragment of working code I've got working from a much larger script; anything broken is because I had to extract the fragment...

  13. #13
    Member TheIdeaMan's Avatar
    Join Date
    Apr 2005
    Posts
    9

    Default

    neo4242002,

    You can find information on how to use cPanel functions via the XML API described on the cPanel XMLAPI page.

    brianoz,

    That's some seriously frightening code! Personally, I'd stick with using API's as their less volatile (or should be) and certainly more readable. For myself, I write my postwwwacct script in PHP, so your code wouldn't work for me.

Similar Threads & Tags
Similar threads

  1. XML API 2 help
    By Dragonxito in forum cPanel Developers
    Replies: 1
    Last Post: 05-13-2011, 05:23 PM
  2. XML-API is any of these possible?
    By neo4242002 in forum cPanel Developers
    Replies: 3
    Last Post: 03-17-2008, 02:46 PM
  3. XML API Milestones
    By JimmyD in forum cPanel Developers
    Replies: 1
    Last Post: 09-19-2007, 01:57 PM
  4. XML API: always get login screen, not XML
    By sldff3ald in forum cPanel Developers
    Replies: 3
    Last Post: 09-19-2007, 10:29 AM
  5. How do I use the xml - api?
    By rhopperger in forum cPanel Developers
    Replies: 3
    Last Post: 05-19-2007, 09:07 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube