{"id":77,"date":"2011-03-25T06:45:00","date_gmt":"2011-03-25T11:45:00","guid":{"rendered":"http:\/\/blogs.wp.stage.cpanel.net\/2011\/03\/introduction_to_cpanel_whm_apis\/"},"modified":"2011-03-25T06:45:00","modified_gmt":"2011-03-25T11:45:00","slug":"introduction_to_cpanel_whm_apis","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/","title":{"rendered":"Introduction to cPanel & WHM APIs"},"content":{"rendered":"

Application Programming Interfaces (APIs) are fundamental to the cPanel & WHM product. APIs allow developers to perform actions (functions) that source and manipulate data related to cPanel accounts and system utilities. Our APIs are used by the cPanel developers when designing new features and interfaces but are also available to 3rd-party developers. In this post, we’ll review the various APIs associated with cPanel and WHM and how you can use them in your own development.<\/p>\n

There are two APIs that affect the cPanel user space: API1 and API2<\/a>. These APIs are used throughout the cPanel interface. In fact, every cPanel interface (i.e., all themes, branding, and pages served in a descendant direct of $server\/base\/frontend\/ ) use these APIs alone to present and alter the end-user’s environment.<\/p>\n

API1 and API2 each have their own set of modules*. Within each module, there is a set functions. For instance, API2’s ‘Email’ module contains a function called ‘listpopswithdisk’ that will list all the details for all of the pop email accounts associated with a cPanel username. API1 modules are listed here<\/a> and API2 modules are listed here<\/a>.<\/p>\n

There are two common, false assumptions about API1 and API2 that confuse many newcomers to cPanel development. The first common misconception is that API1 begat API2. API1 and API2 are not ancestrally related. It is true that API1 was the first publicly available API in cPanel;however, development on API2 did not occur after API1. Both versions of the API were concurrently developed for several years. API1 is considered fully matured at this point in time. Active development has stopped, but API1 is maintained for bugs, security, and (as necessary) forward compatibility. The second common misconception is is that all API1 modules (and their functions) are available in API2. Sometimes, I hear the opposite, that all API2 module and functions are available in API1. Neither of these statements are true. Both API1 and API2 have their particular modules (and their functions) due, in large part, to the organic growth of the cPanel & WHM product. It is not uncommon for a module of the same name, present in both API1 and API2, to have different functions. It most cases, if a particular function exists in both API1 and API2, we recommend using API2.<\/p>\n

API1 was originally designed to be a front-end-only API for use in cPanel pages. Because of this, API1 calls print their output directly to STDOUT. In various parts of the product, that output is suppressed or redirected due to the context of its usage. However, this is the exception to the rule and wouldn’t occur within a cPanel end-user interface. Since API1 was designed for use by a browsable interface, it is not out of the ordinary for an API1 function to generate a snippet of HTML**. API2, on the other hand, always returns a Perl hash structure. While this makes getting raw data much easier, it adds a layer of complexity for front end developers. (But it’s so much more flexible<\/a>! Which is why we prefer API2 functions where possible). Both API1 and API2 calls can be accessed within cPanel pages and their front end usage is described here<\/a> and here<\/a>, respectively.<\/p>\n

The XML-API<\/a> can perform actions that are found within the WHM interface. The XML-API was written specifically for remote interactions with cPanel & WHM. That means that a developer must make an HTTP query to invoke the desired function. While the XML-API covers a lot of functionality, the breadth of utility does not cover as much ground as API1 and API2. so the function sets aren’t compartmentalized into modules. However, in our documentation<\/a>, you will find those functions within logical groupings, like “Account functions” and “SSL functions.”<\/p>\n

The XML-API, like the name suggests, will return XML formatted results. We also offer a JSON version. The interface (aka, HTTP request format) is the same, it’s just a different path in the URL. Unconventionally, it is completely commonplace to see both the XML and the JSON response\/query types referred to as XML-API, despite the obvious discrepancy in the API’s name.<\/p>\n

As it was mentioned earlier, the XML-API can source and manipulate data similar to actions found in the WHM interface. Informally, we call these XML-API functions “native” since they are built right into the XML-API query parser. These native functions are performed as the authenticated, privileged WHM user, namely “root” or a reseller account. This is an important distinction since the XML-API can also perform cPanel actions as a privileged user or end-user! The XML-API can be used as a proxy for API1 and API2 functions. This proxy style query parser is available to all users. If a privileged user makes an API1 or API2 call via the XML-API on either the WHM or cPanel ports, the action will be performed as the user they specify, provided they clear any relevant ACL checks. If a cPanel end-user makes an API1 or API2 call, authenticated as themselves, via the XML-API on a cPanel port, it will perform the action as if from a cPanel page. Details about invoking the XML-API are here<\/a>. Specific information about calling API1 and API2 functions via the XML-API can be found here<\/a>.<\/p>\n

There is one other API currently available to developers that should be mentioned. The Manage2 API provides the utility for managing cPanel licenses. The Manage2 API is primarily for those interested in creating a custom interface for viewing and updating their cPanel licenses. Being an HTTP query, these functions are queried in a similar fashion to the XML-API. The response can be formatted in XML, JSON, or YAML. The Manage2 API is documented here<\/a>.<\/p>\n

In case you missed Matt Dees’ post<\/a> from earlier this month, he announced the official release of cPanel::PublicAPI. It’s available for download on CPAN<\/a> and our Github repository<\/a>. This is an excellent package for querying these APIs (and some other stuff too) in Perl. For PHP folk, we have the XML-API PHP client class, available on our Github repository<\/a>.<\/p>\n

There is always good information and helpful people in the Developer Discussions<\/a> forum. Please don’t hesitate to ask questions or make comments. We really appreciate the input as we review our previous implementations and design new ones. This year promises to be filled with lots of new integration utilities and functionality, so stay tuned!<\/p>\n

* The API1 and API2 modules are called “modules” because of their correlation to the “Cpanel” Perl module namespace. However, these API calls actually pass through a request parser before action is delegated to the end Perl subroutine. So, there wouldn’t be a one-to-one relationship with the API module\/functions and the Perl module\/subroutines.<\/p>\n

** If a particular API1 call renders HTML, it is likely to do the same in the body of an XML-API request too. Since HTML is not XML, but the entire response will likely be treated as such by an XML parser, be careful as you might not receive a well-formed response.<\/p>\n","protected":false},"excerpt":{"rendered":"

Application Programming Interfaces (APIs) are fundamental to the cPanel & WHM product. APIs allow developers to perform actions (functions) that source and manipulate data related to cPanel accounts and system utilities. Our APIs are used by the cPanel developers when designing new features and interfaces but are also available to 3rd-party developers. In this post, […]<\/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":[],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-products"],"acf":[],"yoast_head":"\nIntroduction to cPanel & WHM APIs | cPanel<\/title>\n <!-- Mirrored from cpanel.net/wp-json/wp/v2/posts/77/ by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 06 Sep 2024 09:53:35 GMT --> <meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=_-2057.html \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to cPanel & WHM APIs | cPanel\" \/>\n<meta property=\"og:description\" content=\"Application Programming Interfaces (APIs) are fundamental to the cPanel & WHM product. APIs allow developers to perform actions (functions) that source and manipulate data related to cPanel accounts and system utilities. Our APIs are used by the cPanel developers when designing new features and interfaces but are also available to 3rd-party developers. In this post, […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/\" \/>\n<meta property=\"og:site_name\" content=\"cPanel\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cpanel\/\" \/>\n<meta property=\"article:published_time\" content=\"2011-03-25T11:45:00+00:00\" \/>\n<meta name=\"author\" content=\"cPanel Community\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cPanel\" \/>\n<meta name=\"twitter:site\" content=\"@cPanel\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cPanel Community\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/\",\"url\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/\",\"name\":\"Introduction to cPanel & WHM APIs | cPanel\",\"isPartOf\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/#website\"},\"datePublished\":\"2011-03-25T11:45:00+00:00\",\"dateModified\":\"2011-03-25T11:45:00+00:00\",\"author\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8\"},\"breadcrumb\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/devel.www.cpanel.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Introduction to cPanel & WHM APIs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#website\",\"url\":\"https:\/\/devel.www.cpanel.net\/\",\"name\":\"cPanel\",\"description\":\"Hosting Platform of Choices\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/devel.www.cpanel.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8\",\"name\":\"cPanel Community\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g\",\"caption\":\"cPanel Community\"},\"description\":\"The web hosting industry's most reliable management solution since 1997. With our first-class support and rich feature set, it's easy to see why our customers and partners make cPanel & WHM their hosting platform of choice. For more information, visit cPanel.net.\",\"sameAs\":[\"https:\/\/cpanel.net\"],\"url\":\"https:\/\/devel.www.cpanel.net\/blog\/author\/cpadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Introduction to cPanel & WHM APIs | cPanel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to cPanel & WHM APIs | cPanel","og_description":"Application Programming Interfaces (APIs) are fundamental to the cPanel & WHM product. APIs allow developers to perform actions (functions) that source and manipulate data related to cPanel accounts and system utilities. Our APIs are used by the cPanel developers when designing new features and interfaces but are also available to 3rd-party developers. In this post, […]","og_url":"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/","og_site_name":"cPanel","article_publisher":"https:\/\/www.facebook.com\/cpanel\/","article_published_time":"2011-03-25T11:45:00+00:00","author":"cPanel Community","twitter_card":"summary_large_image","twitter_creator":"@cPanel","twitter_site":"@cPanel","twitter_misc":{"Written by":"cPanel Community","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/","url":"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/","name":"Introduction to cPanel & WHM APIs | cPanel","isPartOf":{"@id":"https:\/\/devel.www.cpanel.net\/#website"},"datePublished":"2011-03-25T11:45:00+00:00","dateModified":"2011-03-25T11:45:00+00:00","author":{"@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8"},"breadcrumb":{"@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/introduction_to_cpanel_whm_apis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/devel.www.cpanel.net\/"},{"@type":"ListItem","position":2,"name":"Introduction to cPanel & WHM APIs"}]},{"@type":"WebSite","@id":"https:\/\/devel.www.cpanel.net\/#website","url":"https:\/\/devel.www.cpanel.net\/","name":"cPanel","description":"Hosting Platform of Choices","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/devel.www.cpanel.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8","name":"cPanel Community","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g","caption":"cPanel Community"},"description":"The web hosting industry's most reliable management solution since 1997. With our first-class support and rich feature set, it's easy to see why our customers and partners make cPanel & WHM their hosting platform of choice. For more information, visit cPanel.net.","sameAs":["https:\/\/cpanel.net"],"url":"https:\/\/devel.www.cpanel.net\/blog\/author\/cpadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts\/77"}],"collection":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/comments?post=77"}],"version-history":[{"count":0,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts\/77\/revisions"}],"wp:attachment":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/media?parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/categories?post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/tags?post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}