This page is specially made to show you how to use DreamHost API and what you will need to use the DreamHost API. Before we start about DreamHost API, lets learn more about API.
API stands for Application Programming Language. API is generally used in backend to communicate between a program and the server. Let’s understand it by example.
Let me take an example of DreamHost API itself. That would be very easier to understand. Let’s say, you want to display the list of DreamHost hosted domain on your website. What will you do? The simple way would be just write down the hosted domains name. Now if you add or remove the host from the DreamHost account then you will have to update the list on your website. If you want to keep the hosted domains list up to date then you will have to update that data every time you add or remove domain from DreamHost.
If you don’t want to go through the trouble of editing the list manually then you can use DreamHost API to display the hosted domains. When DreamHost API is used to display the list of hosted domain, the list is generated dynamically at the time of page loading. Since the list is generate in real time, you get the latest information. Now we can say that you are using API to generate the hosted domains. In other words, your web site uses API to communicate to the DreamHost server.
I assume you now understand what is API.
How To Use DreamHost API?
You can easily integrate DreamHost API in your programs. You will only need to visit the special DreamHost API URL. DreamHost will return the results in tab-delimited format. So before you integrate the API URL to your program, first visit the API URL in the browser. If your API URL format is correct then you will see the tab-delimited web page. You can now use the same URL in to your program.
What You Need?
You will need to have DreamHost API URL to use the API. You can create the API URL from two parameters. One is key and the other is cmd. Key is a unique string of identification. With the value of key, DreamHost understand whose account is being accessed. CMD is an operation name. In cmd variable, you specify which function do you want to perform on the account.
Key is an very important part of the API URL. Don’t make it public. It the key is stolen then your DreamHost account will be at risk. So I would suggest you to create different keys for different operations. You can generate the key at https://panel.dreamhost.com/index.cgi?tree=home.api& .
While creating key, only select those functions which you really want to use. Don’t create a single key by selecting all functions.
How to Create DreamHost API URL?
As I said earlier, to use the DreamHost API, you will need to use API URL. To create the API URL, we will use https://api.dreamhost.com/ . Now you need to append two variable to this URL. This is how the final URL will look like.
You will be able to generate the new key from the API page. The value of the CMD is a function name. On the API page, select the functions for which you want to give the access. Then generate the key. Get more details about functions at http://wiki.dreamhost.com/API .
You may need to append some more variable depending the function selected. You will get the details about extra variables on the DreamHost Wiki. If you select the function to display a list of subscribers on your announcement list then you will need to append two variable. One is for domain name and another is for list name. The working URL for that looks like following.
Which Functions Available In DreamHost API?
At current stage, you may not be able to access all the features of DreamHost panel using API but you can access most of the features. Get the full list from DreamHost API section page.
As of now, there are 76 functions which are available through API. Here is the current list of all functions.
PHP Example of DreamHost API
On DreamHost API wiki, you will get the example of how to use API. The example is in bash script. Here I am offering you a PHP example. In the demo, we will use the above API URL which displays the subscribers details for a given list name. Here is a PHP code.
<?php // Use your API url $url = 'https://api.dreamhost.com/?key=6SHU5P2HLDAYECUM&cmd=announcement_list-list_subscribers&listname=dumb&domain=filesforever.com&format=html'; $curl = curl_init () or die ('curl_init() failed'); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt ($curl, CURLOPT_TIMEOUT, 5); curl_setopt ($curl, CURLOPT_URL, $url); $data = curl_exec ($curl); curl_close ($curl); echo $data; ?>
In the above example, we use curl library to browse the API URL. The returned data is saved in $data variable. You can perform different operations on $data and display it on your webpage.
DreamHost API Applications
There are many developers who are very enthusiastic. Such developers has made applications which uses DreamHost API to perform different operation. If you are going to create one application which uses DreamHost API then I suggest you to have a look at DreamHost API Apps. It might happen that somebody might have already created your app.
Now go ahead and create your first API key.