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
#!/bin/bash
REQUEST_URL="/test_connection/"
BASE_URL="https://your-host-name:5555/api/v1"
# Default base url
# BASE_URL="https://your-host-name:5555/api"
# Version specific base url
# BASE_URL="https://your-host-name:5555/api/v1"
API_URL="$BASE_URL$REQUEST_URL"
/usr/bin/curl -X POST "$API_URL" \
-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 requestVERSION url
request_url='/test_connection/'RULES
# The---------------------------------------------------------------------
server# apiDefault baseAPI url(stable):
base_url='# https://your-host-name:5555/api'api/
#
# Versioned API (recommended for production / future compatibility):
# https://your-host-name:5555/api/v1/
#
# Endpoint example:
# test_connection/
# Full versioned URL:
# https://your-host-name:5555/api/v1/test_connection/
# ---------------------------------------------------------------------
# REQUEST URL
request_url = "/test_connection/"
# BASE URL
base_url = "https://your-host-name:5555/api/v1"
# Default base url
# base_url='base_url = "https://your-host-name:5555/api'api"
# Version-Version specific base url
# base_url='base_url = "https://your-host-name:5555/api/v1'v1"
# TheFINAL apiAPI urlURL
api_url=base_url+api_url = base_url + request_url
# TheAuthentication headerheaders (new API format)
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 BaseVERSION URL OptionsRULES
|--------------------------------------------------------------------------
| Default API:API (stable):
| $base_url = 'https://your-host-name:5555/api';api/
|
| Versioned API (recommended)recommended for production / future compatibility):
| $base_url = 'https://your-host-name:5555/api/v1';v1/
|
| Endpoint example:
| test_connection/
| Full versioned URL:
| https://your-host-name:5555/api/v1/test_connection/
|--------------------------------------------------------------------------
*/
// BaseREQUEST URL
$request_url = "/test_connection/";
// BASE URL
$base_url = '"https://your-host-name:5555/api'api/v1";
// VersionDefault specificbase API URL (uncomment if needed)url
// $base_url = '"https://your-host-name:5555/api"
// Version specific base url
// $base_url = "https://your-host-name:5555/api/v1';v1"
// FullFINAL API URL
$api_url = $base_url . $request_url;
// Initialize cURL
$ch = curl_init($api_url);
// No POST payload for test_connectionrequired
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'eenos_api",
'"X-API-PASSWORD: eenos123'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);
?>