Creating Domain name entries in Linode DNS using the Linode API

Posted on May 6th, 2010 by Mahesh Murali

Linode is a popular Virtual Private Server (VPS) service provider which provides quality linux VPS services at affordable prices. Linode allows programmers to create domain name entries in the Domain manager using a language of your choice via their API.  This article describes how domains can be created programatically using PHP.

To use Linode API:

  • Needs Linode account
  • A user must have a Linode account to use the Api. A user can only perform the operations and actions on instances they have access.

  • All requests require an API key except User.GetAPIKey()
  • User.GetAPIKey() can be used to acquire or generate a user’s API key through the API itself.
    The API key can also be generated or regenerated any time via users profile page in linode site.

API Request format:

https://api.linode.com/?api_key=miasgyas09346hwejgn&api_action=domain.list&DomainID=87463

api_action – This parameter is a must to all requests.
domain.list – specifies the api method which the user wants
The last part of the url specifies the parameters needed for the execution of the method.
There can also be an optional parameter with the request: api_responseFormat.

In the above request the method to execute is domain.list and the parameter passes is the domain id.

API response format:

The optional parameter api_responseFormat can be set to either “json”, “wddx” or “human”.
The default is to output responses in JSON format.

Multiple Requests

The api supports supplying multiple requests that gives an array of responses.The format is

https://api.linode.com/?api_key=miasgyas09346hwejgn&api_action=batch&
api_requestArray=[{"api_action": "test.echo", "foo": "bar"},
{"api_action": "test.echo", "testing": "linodeapi"}]

Some api methods with php code samples:

domain.create

This methods create a domain record.

<?php
function add_linode_domain($domain, $sitesSubDomain, $api_key){

	$json_url = "https://api.linode.com/?api_key=$api_key&api_action=domain.create&Domain=$domain&Type=master&SOA_Email=youremail@anydomain.com";

	$json = file_get_contents($json_url,0,null,null);
	$json_output = json_decode($json);
	if(count($json_output->ERRORARRAY) > 0)
		return 0;
	else{									

		return $jsonOutputList->DATA->DomainID;	//Returns the id of newly created domain record.				

	 }								

}
?>

domain.resource.create

<?php
function add_linode_arecord($domain_id, $sub_domain, $target, $api_key){

	$url_add = "https://api.linode.com/?api_key=".$api_key."&api_action=domain.resource.create&DomainID=$domain_id&Type=A&Target=$target&Name=$sub_domain";

	$json_file = file_get_contents($url_add,0,null,null);
	$json_file_output = json_decode($json_file);
	if(count($json_file_output->ERRORARRAY) DATA->ResourceID;//returns a unique resource id of the new added item.
	}else
	     return 0;									    

	}
}
?>

domain.resource.delete

This method deletes a resource

<?php
function delete_linode_subdomain($domain_id, $resource_id, $api_key, $target){

	$url_del = "https://api.linode.com/?api_key=".$api_key."&api_action=domain.resource.delete&DomainID=$domain_id&ResourceID=$resource_id";

	$json_file = file_get_contents($url_del, 0, null, null);
	$json_file_output = json_decode($json_file);
	if(count($json_file_output->ERRORARRAY) DATA->ResourceID;
	}else
		return 0;

}
?>

domain.resource.list

This returns the list of resources of a particular domain.

<?php
function list_linode_subdomains($domain_id, $api_key){

	$json_url = "https://api.linode.com/?api_key=$api_key&api_action=domain.resource.list&DomainID=$domain_id";

	$json_file = file_get_contents($json_url,0,null,null);
	$json_output = json_decode($json_file);
	if(count($json_output->ERRORARRAY) > 0)
		return 0;//return zero if the result is an error

	foreach ( $json_output->DATA as $data ){

		print_r($data);
	}
	return 0;
}
?>

For more information on linode domain please refer http://www.linode.com/api/.

  • Share/Save/Bookmark

2 Responses to “Creating Domain name entries in Linode DNS using the Linode API”

  1. Kriti Raj Says:

    Hi,
    I am building a website where new web account be created.
    I have to register a domain name against new created account.
    Is this possible with api.linode.com.
    I am using bluehost.

  2. Shibu Basheer Says:

    Hi Kriti,

    You can use the linode api only if you your name servers are pointing to linode nameservers.

    If you are setting up a new server, you should book a new name from from godaddy.com and then point the name server to your service provider (bluehost).

    Thanks,
    Shibu

Leave a Reply