{"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 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 cPanel users could run the same command by simply\u00a0removing the flag identifying the user:<\/p>\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>\nHow to use the Command Line API utilities<\/h2>\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
\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
\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
\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
Where to go for help<\/h2>\n