[MOFH] Basic API Authentication
#1
Hello all,

I want to create a simple application with the MyOwnfreehost cpanel API and tried a few things but I'm not getting any kind of response from the API server. Either I'm overlooking something or there is a problem on MOFH side, but unfortunately I can't submit any support tickets to ifastnet at the moment (403 - "You don't have permission to access /add.php on this server").


Setup WHM API

Quote:Before you can use the API you MUST enter an ip address that you will be making the api calls from
Obviously IP of the server you use to connect.


Quote:To get the most of our this API you should either code your own registration script based exactly on the
cPanel xml-api documentation here (dead link)
https://web.archive.org/web/201112111903...Kit/XmlApi

At this point I have: API server URL, API Username, API Password and 'MyOwnFreehost IP address to connect to'.


The first thing I tried was a PHP example based from the cpanel documentation Guide to API Authentication

PHP Code:
$whmusername "";// API Username
$whmpassword "";// API Password

$query "https://panel.myownfreehost.net:2087/xml-api/applist"//API server URL
 
$curl curl_init();
curl_setopt($curlCURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curlCURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curlCURLOPT_HEADER,0);
curl_setopt($curlCURLOPT_RETURNTRANSFER,1);
$header[0] = "Authorization: Basic " base64_encode($whmusername.":".$whmpassword) . "\n\r";
curl_setopt($curlCURLOPT_HTTPHEADER$header);
curl_setopt($curlCURLOPT_URL$query);
$result curl_exec($curl);
if (
$result == false) {
 
   error_log("curl_exec threw error \"" curl_error($curl) . "\" for $query");
}
curl_close($curl);
 
print 
$result


But I'm not getting anything back. Also tried with this xmlapi-php class from cpanel at github.
If anyone can point out what I'm doing wrong here or show some example of how it should be done I would highly appreciate it!
  Reply
#2
applist is not a function in the MOFH api, id suggest testing using the 'version' api call which is there.
  Reply
#3
Only functions to create, suspend and unsuspend accounts are available. The parameters are the same as the cPanel API, the xmlapi-php class should work fine for that.
Owner of InfinityFree (formerly Grendel Hosting) and XVHOST.
  Reply
#4
Thanks for the replies. I tried from a different server and got it to work. I actually tried from 5 different locations and turns out only one of them was able to connect to the API server.
  Reply
#5
If MOFH auto assigns a username, then what would you use for the username parameter when creating a account?
Founder of website-me.ga
  Reply
#6
(02-06-2017, 06:23 PM)Dog2puppy Wrote: If MOFH auto assigns a username, then what would you use for the username parameter when creating a account?

I just generate a random string for that, and store the one returned by MOFH. Doesn't seem to be particularly important, although they do something with that parameter, since you can use it to login.
  Reply
#7
(02-06-2017, 09:03 PM)Eric Wrote:
(02-06-2017, 06:23 PM)Dog2puppy Wrote: If MOFH auto assigns a username, then what would you use for the username parameter when creating a account?

I just generate a random string for that, and store the one returned by MOFH. Doesn't seem to be particularly important, although they do something with that parameter, since you can use it to login.

Okay. For the domain parameter, would you set it to username.myhost.tld?
Founder of website-me.ga
  Reply
#8
(02-06-2017, 06:23 PM)Dog2puppy Wrote: If MOFH auto assigns a username, then what would you use for the username parameter when creating a account?

The submitted username is used for password changes, suspension and unsuspension.

(02-07-2017, 06:39 AM)Dog2puppy Wrote: Okay. For the domain parameter, would you set it to username.myhost.tld?

That's possible, although you could also enter a custom domain name there (although it needs to point to the byet nameservers before the account can be created).
Owner of InfinityFree (formerly Grendel Hosting) and XVHOST.
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)