How to make request to DirectAdmin with REST API?

divz

New member
Joined
Jul 18, 2017
Messages
1
Does anyone know how I can make a query for API from DirectAdmin? https://www.directadmin.com/api.php

I'm using AngularJS + .NET and I communicate with services via REST API - POST, GET, UPDATE, DELETE etc. but in documentation from directadmin there is not any URL where I can make request. There are only Commands: CMD_ACCOUNT_RESELLER etc. I guess this is for PHP services. So how can I communicate with that API in "normal way"?
 
There is no REST API for DirectAdmin, and what you see is the "normal way". It's language agnostic, and works with PHP, Ruby, .NET, and every other language that can make an HTTP request.
 
Bare in mind that the DA API format was made like 14 years ago; at which time the REST format was no way the standard that it is today.

Screenshot-2016-11-01-16.01.29.png
Source: https://blog.readme.io/the-history-of-rest-apis/

A very basic PHP example is this:

PHP:
<?php

$x = file_get_contents('https://admin:yourpass@hostname:2222/CMD_API_SHOW_USER_USAGE?user=admin');

$y = urldecode($x);

parse_str($y, $output);

print_r($output);

?>

I just tested this; this returns an array with the info from the API.

Note:

So basically you need to make a simple http request, with basic authentication: https://en.wikipedia.org/wiki/Basic_access_authentication

Then you need to decode the url, and parse it. You could search for replacement functions of urldecode and parse_str for your language; usually those are easily found in any popular language.
 
Back
Top