Skip to main content
cPanel Technical Support has been heavily impacted by hurricane Beryl and our ability to respond to tickets has been hindered as a result. We appreciate your understanding and patience as we address these delays.

How to get all email accounts by API?



  • cPRex Jurassic Moderator
    Hey there! Unfortunately I don't. Everything you've found about looping through Return email accounts with each user is the best option I have at this time.
  • cPanelThomas
    Well, it's not *really* that difficult in my estimation. Basically the process is: * Get the accounts via `listaccts` API call * Iterate over accounts and run `list_pops_for` API call on each of them (or use WHMAPI batch to run it for all of them in one shot -- that'd probably be the best way). Thankfully, does not impose any RFC based restrictions on URL length, so even a GET with 1000 accounts specified in the batch call should still work properly. That said, I'd probably submit that one as a POST just to avoid sending usernames over the wire unencrypted (as all URLs go across that way). An example of the output when using the CLI looks like: # bin/whmapi1 --output=jsonpretty batch command='list_pops_for?user=cptest' command='list_pops_for?user=reselleur' { "data" : { "result" : [ { "data" : { "pops" : [ "test@cptest.local" ] }, "metadata" : { "command" : "list_pops_for", "reason" : "OK", "result" : 1, "version" : 1 } }, { "data" : { "pops" : [] }, "metadata" : { "command" : "list_pops_for", "reason" : "OK", "result" : 1, "version" : 1 } } ] }, "metadata" : { "command" : "batch", "reason" : "OK", "result" : 1, "version" : 1 } }
    Of course for an HTTP request, you'd want to URI encode the values passed in as command
    if doing this as a GET, but that should go without saying (and our docs for batch also mention this).
  • Yuriy Revido
    Thanks! The batch function seems to be really useful

Please sign in to leave a comment.