In version 1.62.8, DirectAdmin introduced the possibility to get the list of document roots via the CMD_API_DOMAIN command. The option to use with the API command is document_root_all

CMD_API_DOMAIN?json=yes&action=document_root_all

DirectAdmin states that the old method to get the document roots (via the CLI command “directadmin –DocumentRoot”) will be deprecated and removed in future versions. So, you are encouraged to use the API way.

There are two ways to use the API command – from the web browser or from the command line.

Method 1 – from the web browser

Just log into your DirectAdmin installation and execute:

https://domain.com:2222/CMD_API_DOMAIN?json=yes&action=document_root_all

The result will be like this:

directadmin document roots
JSON DA document roots

You can save the file and use tools/commands to extract the data you need.

Method 2 – from the command line

This method, offers, of course, more rapid possibilities for handling the result data. To execute the API command from command one, you must first authenticate to DA with:

/usr/local/directadmin/directadmin --root-auth-url-for=USERNAME
/usr/local/directadmin/directadmin --root-auth-url-for=admin

So, the full command to get all the document roots on the server is:

curl -s "$(/usr/local/directadmin/directadmin --root-auth-url-for=admin)/CMD_API_DOMAIN?action=document_root_all"
{
	"users": 
	{
		"plothost": 
		{
			"domains": 
			{
				"plothost.com": 
				{
					"private_html": "/home/plothost/domains/plothost.com/private_html",
					"public_html": "/home/plothost/domains/plothost.com/public_html",
					"subdomains": 
					{
					}
				}
			}
		}
       }
}

Most of the time, you will want just a clean list of public_html documents roots, one per line. To get such a result, we must clean up a little the result. Use this command:

curl -s "$(/usr/local/directadmin/directadmin --root-auth-url-for=admin)/CMD_API_DOMAIN?action=document_root_all" | grep public_html | tr -d '":"' | tr -d ',' |  sed 's/public_html //g' | tr -d 't'

and the result will be:

/home/user1/domains/domain1.com/public_html
/home/user2/domains/domain2.com/public_html
....

Links:
API call for document roots
DA version history