Connect and Test API Login
Now Test The API Logins
From the previous page, you created an api account on your WAP control panel. We are not testing the API connection using that api user credentials.
Let's use the following example api user credentials to demonstrate the api login.
Request Header
X-API-USER=eenos_api, you should use the created api username
X-API-PASSWORD=eenos123, you should use the password of the api user
API URL = https://your-host-name:5555/api/
Sample Curl Command
curl -X POST \
-H "X-API-USER: eenos_api" \
-H "X-API-PASSWORD: eenos123" \
https://your-host-name:5555/api/
Output:
{"username":"eenos_api","auth":"API"}
If you can see a similar result like above, your API logins are ok and working. If you got any other error message, then you are using the wrong api logins or there is an error in connecting from your IP.
Python Code
import requests
from pprint import pprint
# API URL
api_url = "https://your-host-name:5555/api/"
# API authentication headers
headers = {
"X-API-USER": "eenos_api",
"X-API-PASSWORD": "eenos123",
}
try:
response = requests.post(api_url, headers=headers)
response.raise_for_status()
pprint(response.json())
except Exception as e:
pprint(str(e))
PHP Code
<?php
// API URL
$url = 'https://your-host-name:5555/api/load-average/';
// Initialize cURL
$ch = curl_init($url);
// Set request options
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-USER: eenos_api',
'X-API-PASSWORD: eenos123'
]);
// Execute request
$result = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo 'cURL Error: ' . curl_error($ch);
} else {
echo $result;
}
// Close cURL
curl_close($ch);
?>