{"id":40922,"date":"2016-04-20T13:00:00","date_gmt":"2016-04-20T18:00:00","guid":{"rendered":"https:\/\/blog.cpanel.com\/?p=40922"},"modified":"2016-04-20T13:00:00","modified_gmt":"2016-04-20T18:00:00","slug":"cpanels-command-line-api-tools","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/","title":{"rendered":"cPanel’s command line API tools"},"content":{"rendered":"

In cPanel & WHM version 11.52\u00a0we released<\/a>\u00a0command line utilities for WHMAPI0<\/a> and WHMAPI1<\/a>. In v56 we have added<\/a>\u00a0command line utilities for the\u00a0cPanel UAPI<\/a>, cPanel API 1<\/a>, and cPanel API 2<\/a>\u00a0as well. All\u00a0of these are meant to help any user, whether root\/reseller or a cPanel user, interact with and test API functions more easily. This will also make adjusting user, account, server, and service settings much easier, and helping to reduce reliance on third party applications like Puppet and Ansible. Overall, as we will see, these tools lead to less time and effort at every step.\u00a0<\/span><\/p>\n

How to use the Command Line API utilities<\/h2>\n

Historically, using the API on any cPanel & WHM server required the user to create a complex script<\/a>, with many potential spots for human error. The command line API utilities are very simple and straightforward to use, and significantly reduce the effort required to interact with cPanel & WHM’s APIs. As root, you have access to both cPanel’s APIs, and WHM’s APIs. For example, if you wanted to use the UAPI call to see the Site Template<\/a> settings for an account with username benny, you would use the SiteTemplates function<\/a> and run the command below. If you are using CloudLinux, you need to use the full path: \/usr\/local\/cpanel\/bin\/uapi<\/p>\n\n\n\n
\n
[root@v56 ~ ]$ uapi --user=benny SiteTemplates list_user_settings\n--- \napiversion: 3\nfunc: list_user_settings\nmodule: SiteTemplates\nresult: \n  data: \n    - \n      documentroot: \/home\/benny\/public_html\n      domain: benny.com\n      homedir: \/home\/benny\n      serveralias: \n        - www.benny.com\n      template_settings: \n        businessHours: 1-7am\n        businessHoursNotes: Closed weekends\n        businessName: benny's business\n        description: This site is pretty nifty.\n        descriptionSectionHeader: other stuff\n        docroot: \/home\/benny\/public_html\n        domain_url: http:\/\/benny.com\n        emailAddress: benny@benny.com\n        facebookLink: ''\n        faxNumber: ''\n        googleMapsURL: ''\n        google_analytics_key: ''\n        is_empty: 0\n        linkedinLink: ''\n        path: \/usr\/local\/cpanel\/etc\/site_templates\n        phoneNumber: ''\n        physicalAddress: ''\n        tagLine: stuff\n        template: business\n        twitterLink: ''\n      type: main_domain\n  errors: ~\n  messages: ~\n  metadata: \n    transformed: 1\n  status: 1\n[root@v56 ~ ]$<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

cPanel users could run the same command by simply\u00a0removing the flag identifying the user:<\/p>\n\n\n\n
\n
[benny@v56 ~]$ uapi SiteTemplates list_user_settings            .<\/span>\n--- \napiversion: 3\nfunc: list_user_settings\nmodule: SiteTemplates\nresult: \n  data: \n    - \n      documentroot: \/home\/benny\/public_html\n      domain: benny.com\n      homedir: \/home\/benny\n      serveralias: \n        - www.benny.com\n      template_settings: \n        businessHours: 1-7am\n        businessHoursNotes: Closed weekends\n        businessName: benny's business\n        description: This site is pretty nifty.\n        descriptionSectionHeader: other stuff\n        docroot: \/home\/benny\/public_html\n        domain_url: http:\/\/benny.com\n        emailAddress: benny@benny.com\n        facebookLink: ''\n        faxNumber: ''\n        googleMapsURL: ''\n        google_analytics_key: ''\n        is_empty: 0\n        linkedinLink: ''\n        path: \/usr\/local\/cpanel\/etc\/site_templates\n        phoneNumber: ''\n        physicalAddress: ''\n        tagLine: stuff\n        template: business\n        twitterLink: ''\n      type: main_domain\n  errors: ~\n  messages: ~\n  metadata: \n    transformed: 1\n  status: 1\n[benny@v56 ~]$<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
<\/div>\n
Attempting to run any of the WHMAPI calls as a user will result in a clear error. For example, trying to check on cPHulk’s status as a user looks like this:<\/div>\n
<\/div>\n
\n\n\n\n
\n
[benny@v56 ~]$ whmapi1 cphulk_status                            .<\/span>\n[whmapi1] This program can only be run by root!\nwhmapi1\nUtility to execute WHM api calls\n       whmapi1 [function] [key=value] [key=value] ....\n       --output=[json|jsonpretty|xml|yaml] \n             The serialization format to use for output.\n       --help Prints this help text.\n[benny@v56 ~]$<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n
<\/div>\n
While running the same command as root gets you the information you desire:<\/div>\n
<\/div>\n
\n\n\n\n
\n
[root@v56 ~ ]$ whmapi1 cphulk_status                            .<\/span>\n--- \ndata: \nis_enabled: 1\nservice: cPHulk\nmetadata: \ncommand: cphulk_status\nreason: OK\nresult: 1\nversion: 1\n[root@v56 ~ ]$<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n
\n

Where to go for help<\/h2>\n

cPanel’s documentation team works very hard to make all of our documentation outstanding, and the Software Development Kit (SDK)<\/a> is no exception. You’ll see documentation provided there for each of our support APIs, as well as the historical documentation for our deprecated APIs, and each function has its own example in multiple programming languages.<\/p>\n

If you can’t find what you need there, or are having trouble with it, cPanel’s forums<\/a> are a great next step. Take a look at the tutorials there, open up a thread with any questions you have.<\/p>\n

__<\/p>\n

Header image courtesy of ToolsAreHome.com<\/a>.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"

In cPanel & WHM version 11.52\u00a0we released\u00a0command line utilities for WHMAPI0 and WHMAPI1. In v56 we have added\u00a0command line utilities for the\u00a0cPanel UAPI, cPanel API 1, and cPanel API 2\u00a0as well. All\u00a0of these are meant to help any user, whether root\/reseller or a cPanel user, interact with and test API functions more easily. This will […]<\/p>\n","protected":false},"author":77,"featured_media":64545,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[49],"tags":[1445,1449,1453,833,1457,1461,1465],"class_list":["post-40922","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-products","tag-cli","tag-command-line","tag-cpanel-api","tag-integration","tag-uapi","tag-whmapi0","tag-whmapi1"],"acf":[],"yoast_head":"\ncPanel's command line API tools | cPanel<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"cPanel's command line API tools | cPanel\" \/>\n<meta property=\"og:description\" content=\"In cPanel & WHM version 11.52\u00a0we released\u00a0command line utilities for WHMAPI0 and WHMAPI1. In v56 we have added\u00a0command line utilities for the\u00a0cPanel UAPI, cPanel API 1, and cPanel API 2\u00a0as well. All\u00a0of these are meant to help any user, whether root\/reseller or a cPanel user, interact with and test API functions more easily. This will […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/\" \/>\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=\"2016-04-20T18:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/devel.www.cpanel.net\/wp-content\/uploads\/2016\/04\/toolssmaller-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1706\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\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=\"3 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\/cpanels-command-line-api-tools\/\",\"url\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/\",\"name\":\"cPanel's command line API tools | cPanel\",\"isPartOf\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/#website\"},\"datePublished\":\"2016-04-20T18:00:00+00:00\",\"dateModified\":\"2016-04-20T18:00:00+00:00\",\"author\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8\"},\"breadcrumb\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/devel.www.cpanel.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"cPanel’s command line API tools\"}]},{\"@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":"cPanel's command line API tools | 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\/cpanels-command-line-api-tools\/","og_locale":"en_US","og_type":"article","og_title":"cPanel's command line API tools | cPanel","og_description":"In cPanel & WHM version 11.52\u00a0we released\u00a0command line utilities for WHMAPI0 and WHMAPI1. In v56 we have added\u00a0command line utilities for the\u00a0cPanel UAPI, cPanel API 1, and cPanel API 2\u00a0as well. All\u00a0of these are meant to help any user, whether root\/reseller or a cPanel user, interact with and test API functions more easily. This will […]","og_url":"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/","og_site_name":"cPanel","article_publisher":"https:\/\/www.facebook.com\/cpanel\/","article_published_time":"2016-04-20T18:00:00+00:00","og_image":[{"width":2560,"height":1706,"url":"https:\/\/devel.www.cpanel.net\/wp-content\/uploads\/2016\/04\/toolssmaller-scaled.jpg","type":"image\/jpeg"}],"author":"cPanel Community","twitter_card":"summary_large_image","twitter_creator":"@cPanel","twitter_site":"@cPanel","twitter_misc":{"Written by":"cPanel Community","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/","url":"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/","name":"cPanel's command line API tools | cPanel","isPartOf":{"@id":"https:\/\/devel.www.cpanel.net\/#website"},"datePublished":"2016-04-20T18:00:00+00:00","dateModified":"2016-04-20T18:00:00+00:00","author":{"@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8"},"breadcrumb":{"@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/cpanels-command-line-api-tools\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/devel.www.cpanel.net\/"},{"@type":"ListItem","position":2,"name":"cPanel’s command line API tools"}]},{"@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\/40922"}],"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=40922"}],"version-history":[{"count":0,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts\/40922\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/media\/64545"}],"wp:attachment":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/media?parent=40922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/categories?post=40922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/tags?post=40922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}