WHM/cPanel API: Difference between revisions

From My Wiki
Jump to navigation Jump to search
Created page, with listing e-mail accounts and mass e-mail account creation at CLI
 
Added paragraph tags for formatting
Line 1: Line 1:
For doing WHM or cPanel tasks at the command line.  
For doing WHM or cPanel tasks at the command line.  
Current documentation: https://api.docs.cpanel.net
<p>Current documentation: https://api.docs.cpanel.net</p>
Their examples currently have --output=jsonpretty listed by default. This isn't necessary if you don't need JSON-pretty output. YAML output is default.  
<p>Their examples currently have ''--output=jsonpretty'' listed by default. This isn't necessary if you don't need JSON-pretty output. YAML output is default. </p>
=cPanel=
=cPanel=
==E-mail Accounts==
==E-mail Accounts==

Revision as of 20:21, February 3, 2022

For doing WHM or cPanel tasks at the command line.

Current documentation: https://api.docs.cpanel.net

Their examples currently have --output=jsonpretty listed by default. This isn't necessary if you don't need JSON-pretty output. YAML output is default.

cPanel

E-mail Accounts

Create list of current e-mail accounts

 uapi --user=CPUSER Email list_pops | grep 'email:' | awk '{print $2}' >> email_accounts.txt

Mass Create E-mail Accounts

This creates them from a list "names" which does not have the @domain.com within it, with an 18-character random password. Fill in the cPanel user and domain name.

for account in $(cat names); do echo $account; uapi --user=CPUSER Email add_pop email='$account' password=`strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 18 | tr -d '\n'` domain='EXAMPLE.COM'; done

This creates them from a list "names" for domain B, with an 18-character random password, and creates forwarders from their counterparts on domain A. Assumes they're in the same cPanel account.

for account in $(cat names); do echo $account; uapi --user=CPUSER Email add_pop email='$account' password=`strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 18 | tr -d '\n'` domain='EXAMPLE.COM'; uapi --user=CPUSER Email add_forwarder domain='OLDEXAMPLE.COM' email='$account@OLDEXAMPLE.COM' fwdopt='fwd'  fwdemail=@account@EXAMPLE.COM; done

WHM