WHM API: Find cPanel User by Domain Made Easy
To find the cPanel user associated with a specific domain using the WHM API, you can use the whmapi1
command-line tool or make an API call to the accountsummary
endpoint. This endpoint returns information about an account, including the associated user, based on a domain name.
Using whmapi1
Command-Line Tool
- Access Your Server:
Connect to your server via SSH.
ssh root@your_server_ip
- Run the
whmapi1
Command:
Use thewhmapi1
command to query the account information by domain.
whmapi1 accountsummary domain=example.com
Replace example.com
with the domain name you are querying.
- Output:
The output will include information about the account, including the username associated with the specified domain.
Using the WHM API Programmatically
You can also make an API call programmatically using cURL or any programming language that supports HTTP requests.
Using cURL
- Construct the cURL Request:
Make sure you have your WHM root access hash or API token. ReplaceYOUR_API_TOKEN
with your actual token andexample.com
with the domain name.
curl -s -H'Authorization: cpanel YOUR_API_TOKEN' "https://yourserver:2087/json-api/accountsummary?api.version=1&domain=example.com"
- Output:
The response will be in JSON format and will include the username associated with the specified domain.
Using a Programming Language (Python Example)
Here’s an example of how you can use Python to make the API call:
- Install Required Library:
Ensure you have therequests
library installed.
pip install requests
- Python Script:
import requests
server = "https://yourserver:2087"
api_token = "YOUR_API_TOKEN"
domain = "example.com"
headers = {
"Authorization": f"cpanel {api_token}"
}
url = f"{server}/json-api/accountsummary?api.version=1&domain={domain}"
response = requests.get(url, headers=headers, verify=False)
if response.status_code == 200:
data = response.json()
if 'data' in data and 'acct' in data['data']:
user = data['data']['acct']['user']
print(f"The cPanel user for domain {domain} is {user}")
else:
print(f"No account found for domain {domain}")
else:
print(f"Error: {response.status_code} - {response.text}")
WHM API Documentation
Refer to the official WHM API documentation for more details and additional parameters you can use with the accountsummary
endpoint: WHM API 1 – accountsummary
Summary
- Using
whmapi1
command: Quick and direct method via SSH. - Using cURL: Simple and effective for scripting.
- Using Python: Flexible and can be integrated into larger applications.
By following these steps, you can easily find the cPanel user associated with a specific domain using the WHM API.