Using the DirectAdmin API: managing your package with scripts
DirectAdmin has an API: a way to manage your package with a script or program instead of with the mouse. Almost everything you do in the panel can also be done via the API. Think of updating a DNS record when your home IP address changes, creating mailboxes from your own software, or retrieving a list of your databases every night.
Can I use the API with my package?
Yes. The API works with every package that includes DirectAdmin: all web hosting packages and also the email packages. Resellers can also use it to manage their own customers' accounts. You don't need to request anything and it doesn't cost extra.
A script has exactly the same rights as you have in DirectAdmin. So it can only access your own package, and only the things your package allows.
How it works
- Address: you talk to the API at the same place where you log in: https://servername:2222. You can find your server name in My WebOké under the package, under Manage.
- Two types of commands: the new API, with addresses starting with /api/ and responses in JSON, and the older API with commands like /CMD_API_.... Start with the new API. Anything not yet available there can be found in the old API. Add ?json=yes to get a response in JSON.
- Logging in: every command sends your DA username and a password (HTTP Basic authentication). Preferably use a login key for this instead of your real DA password, see below.
- Documentation in your own panel: in DirectAdmin, under Support & Help, you'll find the API Documentation. There you can see all the commands of the new API and try them out immediately with your own account.
An example
Use this command to request the databases of your package. Replace user, key and servername with your own details:
curl -u 'user:key' https://servername:2222/api/db-show/databases
You'll get a list back in JSON. It works the same way from PHP, Python, or any other language that can request a web address.
Working safely with a login key
Never give a script your regular DA password. In DirectAdmin, under Login Keys, create a separate key. This kind of key can be restricted:
- to only the commands the script actually needs;
- to only the IP address of the computer or server where the script runs;
- with an expiry date, if you only need the access briefly.
In any case, exclude the commands CMD_LOGIN_KEYS and CMD_PASSWD, so the key can't create new keys and can't change your password. If the key does leak, delete it and create a new one, without having to change your password.
How to create a key is explained step by step in the DirectAdmin manual: Login Keys: logging in for scripts and programs.
Good to know
- If a script repeatedly tries to log in with an incorrect password or key, our firewall will block that IP address. Check Am I blocked? if your script suddenly can't connect anymore.
- We're happy to help if the API itself isn't working, but we don't write or check custom scripts. Use the DirectAdmin documentation below for that.
- Would you rather manage your hosting with Claude, ChatGPT or Mistral, without programming yourself? Check out our MCP server for AI.
DirectAdmin documentation
DirectAdmin's documentation is in English:
- API Access: how the API works, logging in, and the different types of API.
- Examples: examples with curl, Bash, PHP and Python.
- Legacy API: the older CMD_API commands and their responses.
- Overview of CMD_API commands: search all older commands.
- Creating a login key: login keys according to DirectAdmin.
See also in the DirectAdmin manual: Finding your server name and DA username.
