test_connection
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 Data
apiuser=eenos_api , you should use the created api user name
apiauth=eenos123, you should use the password of the api user
API URL = https://your-host-name:5555/api/
Sample Curl Command
curl -X POST -d "apiuser=eenos_api&apiauth=eenos123" https://your-host-name:5555/api/
Output:
{"username":"eenos_api","auth":"API"}
If you could see a similar result like below, 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
# The api url
api_ulr=' https://your-host-name:5555/api/'
# The data in dictionary format
data={
'apiuser': 'eenos_api',
'apiauth':'eenos123'
}
try:
result=requests.post(api_ulr, data = data)
pprint(result.json())
except Exception as e:
pprint(str(e))
pass
PHP Code
<?php
// The API URL
$url='https://your-host-name:5555/api/';
//The data you want to send via POST
$fields= [
'apiuser' => 'eenos_api',
'apiauth' => 'eenos123'
];
//url-ify the data for the POST
$fields_string = http_build_query($fields);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
echo $result;
?>