As network administrators, you constantly seek tools that simplify and enhance your workflow. The Admiral Platform API is designed to do just that, offering features for managing your MikroTik hardware efficiently. In this post, we’ll introduce you to the Admiral Platform API and guide you through the steps to get started. Look for additional details in the API Guide linked below.
What is the Admiral Platform API? #
The Admiral Platform API provides an interface for interacting with your Admiral routers programmatically. Whether you manage internet services for small businesses or oversee larger networks, the API offers flexibility and control, enabling you to automate tasks, monitor performance, and integrate with other tools seamlessly.
Getting Started with Admiral Platform API #
Follow these steps to start using the Admiral Platform API:
1. Sign Up and Obtain API Credentials #
First, you need to sign up for an account on the Admiral Platform website. Once registered, navigate to Admin Settings and generate your API credentials. These credentials are necessary for authenticating your requests. The credentials are only displayed once, so be sure to copy the key.
2. Set Up Your Development Environment & Explore API Guide #
Ensure you have the necessary tools installed. You will need:
- A programming language of your choice (Python, JavaScript, etc.)
- An HTTP client library (requests for Python, Axios for JavaScript)
- A text editor or IDE
- Optional Testing Environment such as PostMan
FORMATTING NOTE: The API Guide documentation does not indicate the need to use a ? mark to offset the parameter in the url string. For example to post to the Add Router : https://app.admiralplatform.com:8080/auth/apiv1/RWBData/router?router_name=TEST #
GET Devices Example: https://app.admiralplatform.com:8080/auth/blog/RWBData/devices?ether1mac=74:4D:28:F6:67:DD
Known API Document Error: in the add router post call above the required input parameter should be router_name instead of name.
3. Authenticate Your Requests #
Before making any API calls, you must authenticate your requests using your API credentials. Here’s an example of how to do this in Python using the requests library:
import requests
api_key = 'your_api_key'
api_secret = 'your_api_secret'
base_url = 'https://api.admiralplatform.com'
headers = {
'Authorization': f'Bearer {api_key}:{api_secret}',
'Content-Type': 'application/json'
}
response = requests.get(f'{base_url}/your-endpoint', headers=headers)
if response.status_code == 200:
print('Authenticated successfully!')
else:
print('Authentication failed:', response.text)
4. Explore Available Endpoints #
The Admiral Platform API offers various endpoints for different functionalities. Review the API documentation to understand the available endpoints and their parameters. Some common endpoints include:
- /routers – Retrieve a list of all devices
- /router/{id} – Get details of a specific router
PostMan Examples
5.Example API Call #
In this example we make a simple API call in Python to fetch a list of devices: (please note this is not an exact example for the API- please follow the documentation within the platform.)
response = requests.get(f'{base_url}/devices', headers=headers)
if response.status_code == 200:
devices = response.json()
for device in devices:
print(f"Device ID: {device['id']}, Name: {device['name']}")
else:
print('Failed to retrieve devices:', response.text)
6. Handle Errors and Responses Example in Python #
Properly handling errors and responses is crucial for robust applications. Always check the status code and handle different responses appropriately. Here’s an example: (please note this is not an exact code example for the Admiral API- please follow the documentation within the platform.)
def fetch_devices():
response = requests.get(f'{base_url}/devices', headers=headers)
if response.status_code == 200:
return response.json()
elif response.status_code == 401:
print('Unauthorized: Check your API credentials')
else:
print(f'Error {response.status_code}: {response.text}')
return None
devices = fetch_devices()
if devices:
for device in devices:
print(f"Device ID: {device['id']}, Name: {device['name']}")
Additional Code Examples: (please note this is not an exact code example for the Admiral API- please follow the documentation within the platform.) #
PHP – cURL
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://example.remotewinbox.com:8080/auth/apiv1/RWBData/router',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'router_name=AdmiralPlatformTest',
CURLOPT_HTTPHEADER => array(
'X-API-KEY: xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz',
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
PHP – Guzzle
<?php
$client = new Client();
$headers = [
'X-API-KEY' => 'xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz',
'Content-Type' => 'application/x-www-form-urlencoded'
];
$options = [
'form_params' => [
'router_name' => 'AdmiralPlatformTest'
]];
$request = new Request('POST', 'https://example.remotewinbox.com:8080/auth/apiv1/RWBData/router', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();
JavaScript – jQuery
var settings = {
"url": "https://example.remotewinbox.com:8080/auth/apiv1/RWBData/router",
"method": "POST",
"timeout": 0,
"headers": {
"X-API-KEY": "xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz",
"Content-Type": "application/x-www-form-urlencoded"
},
"data": {
"router_name": "AdmiralPlatformTest"
}
};
$.ajax(settings).done(function (response) {
console.log(response);
});
Python – Requests
import requests
url = "https://example.remotewinbox.com:8080/auth/apiv1/RWBData/router"
payload = 'router_name=AdmiralPlatformTest'
headers = {
'X-API-KEY': 'xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyz',
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
7. Integrate with Your Workflow #
Once comfortable with the basics, integrate the API into your workflow. Automate routine tasks, gather insights through data analysis, and build custom applications to enhance your network management capabilities.
With Admiral Platform API integration, you have the tools needed to streamline operations and improve efficiency. Happy coding!
Read the Latest News from Our Blog… #
- Admiral Updates – November 2024
- Tips4Tiks – What are FCS errors?
- Avoid Default User Security Flaws – How to Create a New User
- Announcing Our New Video Series: Bridge Mode, Episode 1!
- Brute Force Login Protection Tips