Connect and Test API Login
Now Test TheTesting API LoginsAccess
FromIn the previous page,step, you created an apiAPI account onin yourthe Eenos WAP controlPortal.
Now we Wewill are not testingtest the API connection using that api userthose credentials.
Example API Credentials
For Let'sdemonstration purposes, we will use the following examplesample apicredentials:
In your actual setup, replace these with the API user
credentialsandtopassworddemonstrateyouthecreated.api login.
Request Header
Every API request must include the following authentication headers:
API Endpoint URL
Use the apibase userAPI URL to send requests:
API URL = https://your-host-name:5555/api/
SampleExample CurlAPI CommandTest Request
You can test the API connection using a simple cURL command:
curl -X POST \
-H "X-API-USER: eenos_api" \
-H "X-API-PASSWORD: eenos123" \
https://your-host-name:5555/api/
Expected Response
Output:If the authentication is successful, you will receive a JSON response similar to:
{"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);
?>
Summary
If the request is successful: