{"id":76,"date":"2011-03-07T11:42:06","date_gmt":"2011-03-07T11:42:06","guid":{"rendered":"http:\/\/blogs.wp.stage.cpanel.net\/2011\/03\/cpanelpublicapi\/"},"modified":"2011-03-07T11:42:06","modified_gmt":"2011-03-07T11:42:06","slug":"cpanelpublicapi","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanelpublicapi\/","title":{"rendered":"cPanel::PublicAPI"},"content":{"rendered":"
Today I posted cPanel::PublicAPI to github. This is a set of perl modules that allows for easy access into cPanel’s APIs from a simple object interface. This module offers several great features:<\/p>\n
To get started, you can install cPanel::PublicAPI via CPAN the source is also available on our\u00a0github repository<\/a>\u00a0if you wish to submit patches\/changes. I strongly suggest reading the\u00a0documentation on CPAN<\/a> to get started.<\/p>\n The following is an example of how to query the XML-API’s listaccts() call using PublicAPI (on a cPanel server, running as root, and an accesshash exists): To query a cpanel account with API2 while authenticated as root, you would do something like the following: You may have noticed that you have to specify the service as the first parameter. It is important to note that even though you may be calling the cpanel API, if you are root or a reseller querying an account that is not the reseller account itself, you will still need to query the whostmgr service. This is because if you authenticate against the cpanel service, you will be querying your user, no mater which user you specify in the \u201cconfig\u201d hash.<\/p>\n If you don’t want cPanel::PublicAPI to auto-detect credentials, you can pass in the user and pass: Or you can specify an access hash: There are tons of other features within this module, I suggest starting out with the POD documentation for cPanel::PublicAPI and going from there. If you have any further questions, please post on our dev forums and we will be happy to help you.<\/p>\n","protected":false},"excerpt":{"rendered":" Today I posted cPanel::PublicAPI to github. This is a set of perl modules that allows for easy access into cPanel’s APIs from a simple object interface. This module offers several great features: Auto-detection of credentials (when available) Support for cPanel’s DNS Clustering API Support for: cPanel, WHM, webmail and non-cPanel services. Minimal dependencies BSD Licensed […]<\/p>\n","protected":false},"author":77,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[49],"tags":[421,425,317,429,433,309],"class_list":["post-76","post","type-post","status-publish","format-standard","hentry","category-products","tag-api1","tag-api2","tag-inside-cpanel","tag-perl","tag-publicapi","tag-xml-api"],"acf":[],"yoast_head":"\n
\n#!\/usr\/bin\/perl
\nuse cPanel::PublicAPI ();
\nuse Data::Dumper;
\nmy $pubapi = cPanel::PublicAPI->new();
\nprint Dumper $pubapi->whm_api('listaccts');<\/code><\/p>\n
\n#!\/usr\/bin\/perl
\nuse\u00a0cPanel::PublicAPI\u00a0();
\nuse\u00a0Data::Dumper\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0();
\nmy\u00a0$pubapi\u00a0=\u00a0cPanel::PublicAPI->new();\u00a0\u00a0\u00a0\u00a0#\u00a0Create\u00a0email\u00a0account
\nprint\u00a0Dumper\u00a0$pubapi->cpanel_api2_request(
\n'whostmgr',
\n{
\n'module'\u00a0=>\u00a0'Email',
\n'func'\u00a0=>\u00a0'addpop',
\n'user'\u00a0=>\u00a0'someuser',
\n},
\n{
\n'domain'\u00a0=>\u00a0'myawesomedomain.com',
\n'email'\u00a0=>\u00a0'localuser',
\n'password'\u00a0=>\u00a0'AS(d0m9d0sad12ea!s',
\n'quota'\u00a0=>\u00a042,
\n}
\n);<\/code><\/p>\n
\nmy $pubapi = cPanel::PublicAPI->new( 'user' => 'someuser', 'pass' => 'sdfkklkasf' );<\/code><\/p>\n
\nmy $pubapi = cPanel::PublicAPI->new( 'user' => 'someuser', 'accesshash' => $contents_of_homedir_slash_dot_acesshash );<\/code><\/p>\n