Skip to main content

test_connection

Now  Test The API LoginsConnection

FromThis thefunction previousis pageto you created  an api account on your WAP control panel.  We are not testingtest the API connection usingto thatthe server via api userrequest credentials.

 Let's  use the following example api user credentials to  demonstrate the api login.itself.

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//test_connection/

SampleRequest URL

Post  URL = /test_connection/

Full URL = https://your-host-name:5555/api/test_connection/

Example Curl Command 

curl  -X POST -d "apiuser=eenos_api&apiauth=eenos123" https://your-host-name:5555/api/test_connection/

Output:

{"username"data":{"test":"eenos_api"Connection Success"},"auth"info":"API"}API Connection Success","status":200}

 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
#!/usr/bin/python3
import requests
from pprint import pprint
# The apiAPI request url
api_ulr=request_url='/test_connection/'
# The server api base url
base_url='https://your-host-name:5555/api'
# Default  base url
# base_url='https://your-host-name:5555/api'
# Version specific base url
# base_url='https://your-host-name:5555/api/'v1'
# The api url 
api_ulr=base_url+request_url
# The data in dictionary format
data={
    'apiuser': 'eenos_api',
    'apiauth':'eenos123',    
    'user':'myclient',   
    'selfown':'on' 
}
try:   
    result=requests.post(api_ulr, data = data)
    pprint(result.json())
except Exception as e:
    pprint(str(e))
    pass
PHP Code
<?php
// The API URLrequest url
$url=request_url='/test_connection/';

// Your server API base url
$base_url='https://your-host-name:5555/api';
// Default base url
// $base_url='https://your-host-name:5555/api';
// Version specific base url
// $base_url='https://your-host-name:5555/api/'v1';
// The FULL API URL
$api_url=$base_url.$request_url;
//The data you want to send via POST
$fields= [
    'apiuser'   =>  'eenos_api',
    'apiauth'   =>  'eenos123',
    'user'      =>  'myclient',   
    'selfown'     =>  'on'
];
//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)api_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);
//Print the json result
echo json_encode(json_decode($result;result), JSON_PRETTY_PRINT);
?>