Skip to main content

test_connection

Test API Connection

This function is to test the API connection to the server via api request itself.

Required Headers

Field Description Example
X-API-USER The API username eenos_api
X-API-PASSWORD The API  user password eenos123

Request URL

Post  URL = /test_connection/

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

Example Curl Command 

curl -X POST \
  -H "X-API-USER: eenos_api" \
  -H "X-API-PASSWORD: eenos123" \
  https://your-host-name:5555/api/test_connection/

Output:

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

 If you can 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_url=base_url+request_url
# The header
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 request URL
$request_url = '/test_connection/';

/*
|--------------------------------------------------------------------------
| API Base URL Options
|--------------------------------------------------------------------------
| Default API:
| $base_url = 'https://your-host-name:5555/api';
|
| Versioned API (recommended):
| $base_url = 'https://your-host-name:5555/api/v1';
|--------------------------------------------------------------------------
*/

// Base URL
$base_url = 'https://your-host-name:5555/api';

// Version specific API URL (uncomment if needed)
// $base_url = 'https://your-host-name:5555/api/v1';

// Full API URL
$api_url = $base_url . $request_url;

// Initialize cURL
$ch = curl_init($api_url);

// No POST payload for test_connection
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Authentication headers (new API format)
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'X-API-USER: eenos_api',
    'X-API-PASSWORD: eenos123'
]);

// Execute request
$result = curl_exec($ch);

// Error handling
if (curl_errno($ch)) {
    echo 'cURL Error: ' . curl_error($ch);
} else {
    echo json_encode(json_decode($result), JSON_PRETTY_PRINT);
}

// Close connection
curl_close($ch);
?>