If you are a new programmer and want to learn how to use DreamHost API then you must first understand what API is & how one can use API.
API stands for Application Programming Interface. API is used to communicate between programs. Sounds difficult to understand? It’s not.
Let me take an example to show you exactly what API is! DreamHost offers API facility to access DreamHost account. Let’s say you are making your personal web site and you want to show all your visitors the list of your sites hosted on your DreamHost account. In normal scenario, you will just write down a list of all sites on the personal web site. Here there is a one drawback. You will have to edit the list every single time you add/remove site from your DreamHost account.
Solution? Use DreamHost API. When you use DreamHost API on your personal web site to access the list of sites hosted with DreamHost, you don’t have to update the list every time you add/remove any site. The list on your web site is dynamically generated at the time of page loading and displays the real time data. The code (which shows list of sites hosted with DreamHost) on your personal web site now using Application Programming Interface(API) to communicate to DreamHost account.
Now I think you have a good idea of what API is!
How To Use DreamHost API?
Using of DreamHost API is very simple. You just need to visit the one simple URL and you will get result in tab-delimited plain text. You can visit the URL using programming language or in web browser. I would suggest you to first use web browser. So you will know that the URL is correct. After that you can implement it in your program.
What You Need?
To access the DreamHost API, you need two main things. 1) key & 2) cmd. Key is an unique identifier string which allows you to access your DreamHost account data. So you need to protect your key. Don’t make it public otherwise your DreamHost account may come at a risk. I would also suggest you to create separate key for separate commands. So you are reducing the risk in case someone gets an access to your key. You can create a key from https://panel.dreamhost.com/index.cgi?tree=home.api& .
While creating the key, select functions which you want to use. Make sure that you don’t create one key with all functions.
How to Create DreamHost API URL?
To make a use of DreamHost API, you need to create specific API URL. Then you need to browse the URL either through program or in web browser.
You will use the URL https://api.dreamhost.com/ . In this URL you need to append two basic variables and their values. So your final URL will be like
The values of cmd is a function name which you want to access by using API. These values you can get from DreamHost wiki at http://wiki.dreamhost.com/API .
You might need more variables and values depending on the function you selected. For our example, in listing domain, you don’t need any extra variable or it’s value. If you want to access the list of subscribers in your announcement list then you will need two more variable. listname & domain. Please make sure that all these variable are case-sensitive. So your DreamHost API URL is also case sensitive. So your final URL will be like this.
All information about variable names, you can get from DreamHost wiki.
Which Functions Available In DreamHost API?
You cannot access all functions of web panel through DreamHost API but still you can access many functions of DreamHost panel using API. You can get a full list of functions from web panel API section.
There are total 76 functions available through DreamHost API at the time of writing this article. Here is a list of all functions available through API.
PHP Example of DreamHost API
In DreamHost Wiki, there is already an example available on how to use DreamHost API but that example is for bash script. I am going to explain you DreamHost API usage in PHP. For example purpose, we will use the above API URL which displays subscribers details for particular listname. Here is a PHP code for that.
<?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 are using curl library to browse the API url. Then the returned data is saved in $data variable. You can use this variable as you like.
DreamHost API Applications
If you have any specific requirement to use DreamHost API, I would suggest you to check DreamHost API Apps at http://wiki.dreamhost.com/API_Apps . You might find your required application already made by someone else.
I hope this article is helpful for all those who want to access DreamHost API.
Go To DreamHost How To.
Go To Home.