Skip to main content

test_connection

Test API Connection

This function is to test the API connection to the server via api request 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/

Request 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:

{"data":{"test":"Connection Success"},"info":"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 API request url
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 request 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, $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), JSON_PRETTY_PRINT);
?>