Table Of Contents

Previous topic

Gandi Site API

Next topic

Site API Reference

Site API


The Gandi Site API provides a set of remote requests to manage your sites. Gandi site are based on website builder provider. Actually, this api is build on top of basekit.

Connect to the API server

The Gandi Site API is provided through a set of XML-RPC calls:

>>> import xmlrpclib
>>> api = xmlrpclib.ServerProxy('')
>>> apikey = 'my 24-character API key'
>>> # Now you can call API methods.
>>> # You must authenticate yourself by passing
>>> # the API key as the first method's argument
>>> version =


In Python, use the xmlrpclib module from the standard library.

In Python 3 xmlrpclib has been renamed xmlrpc.client.

// Library installed from PEAR
require_once 'XML/RPC2/Client.php';

// The first step is to connect to the API
$version_api = XML_RPC2_Client::create(
    array( 'prefix' => 'version.', 'sslverify' => True )

// Warning !
// PEAR::XML_RPC2 checks the SSL certificate with Curl
// Curl has its own CA bundle so you may :
// * disable the 'sslverify' option: leads to security issue
// * enable the 'sslverify' option (default) and add the Gandi
// SSL certificate to the Curl bundle: best choice for security
// See:

$apikey = 'my 24-character API key';

// Now you can call API method
// You must authenticate yourself by passing the API key
// as the first method's argument
$result = $version_api->info($apikey);

// Warning !
// PEAR::XML_RPC2 has known bugs on methods calls
// See
// You may use this call instead of the above one :
// $result = $version_api->__call("info", $apikey);

// dump the result


In PHP 5, use the XML_RPC2 package from pear.

XML_RPC2 works with ‘prefix’ in order to bind to namespace. The ‘prefix’ isn’t editable, so you have to instanciante a client by namespace.

> var xmlrpc = require('xmlrpc')
> var api = xmlrpc.createSecureClient({
...  host: '',
...  port: 443,
...  path: '/xmlrpc/'
... })
> var apikey = 'my 24-character API key'
> // Now you can call API methods.
> // You must authenticate yourself by passing the API key
> // as the first method's argument
> api.methodCall('', [apikey], function (error, value) {
...  console.dir(value)
... })


With NodeJS, use the npm xmlrpc package.

use XML::RPC;

my $api = XML::RPC->new('');

my $apikey = 'my 24-character API key';

# Now you can call API methods.
# You must authenticate yourself by passing the API key
# as the first method's argument
my $version = $api->call( '', $apikey );


With perl, use the cpan xml::rpc package.

require 'xmlrpc/client'

class ZlibParserDecorator
  def initialize(parser)
    @parser = parser
  def parseMethodResponse(responseText)
  def parseMethodCall(*args)

server = XMLRPC::Client.new2('')
server.http_header_extra = { "Accept-Encoding" => "gzip" }

apikey = 'my 24-character API key'

# Now you can call API methods.
# You must authenticate yourself by passing the API key
# as the first method's argument
version ="", apikey)


With ruby, use the xmlrpc/client module from the standard library. Ruby does not support gzip by default, the ZlibParserDecorator is used to enabled with Ruby >1.9.

For older ruby version, neither set the http_header_extra nor the parser.


To avoid RuntimeError with ruby >= 1.9, add:

XMLRPC::Config.module_eval {
    const_set(:ENABLE_NIL_PARSER, true)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <xmlrpc.h>
#include <xmlrpc_client.h>

#define CLIENT_NAME             "Documentation Client"
#define CLIENT_VERSION          "0.1"

#define SERVER_URL              ""

int     client_connect(xmlrpc_env *);
void    client_check_fault(xmlrpc_env *);

main(int argc, char **argv)
        xmlrpc_env      env;
        xmlrpc_value    *apikey, *rv;


        apikey = xmlrpc_build_value(&env, "(s)", "my 24-character API key");
        rv = xmlrpc_client_call_params(&env, SERVER_URL, "", apikey);



        return (0);

client_connect(xmlrpc_env *env)
        struct xmlrpc_clientparms clientp;
        struct xmlrpc_curl_xportparms curlp;

        curlp.network_interface = NULL;         /* use curl's default */
        curlp.ssl_verifypeer = 1;               /* Gandi API CA must be present */
        curlp.ssl_verifyhost = 2;
        curlp.user_agent = CLIENT_USERAGENT;    /* XML-RPC requirement */

        clientp.transport = "curl";
        clientp.transportparmsP = &curlp;
        clientp.transportparm_size = XMLRPC_CXPSIZE(user_agent);

        xmlrpc_client_init2(env, XMLRPC_CLIENT_NO_FLAGS, CLIENT_NAME,
            CLIENT_VERSION, &clientp, XMLRPC_CPSIZE(transportparm_size));

        return (1);

client_check_fault(xmlrpc_env *env)
        if (env->fault_occurred) {
                fprintf(stderr, "XML-RPC Fault: %s (%d)\n", env->fault_string,


With C, use the xmlrpc-c library.

Site Management

List your sites

To list the sites you own, just call the site.list() method:


Count your sites

To count sites you own, just call the site.count() method:


Get info on a site

Get info on an instance with method method:

>>>, 1)

Create a site

To create a site, use the site.create() method by specifying a name, virtual hosts and other optional parameters.

>>> site_spec = {
    'name': 'My Site',
    'provider': 'basekit_whitelabel',
    'vhosts': [''],
    'duration': '3m'}
>>> op =, site_spec)
>>> op['type']

Then, you have to wait that the operation has succeed for continue.

>>> import time
>>> while op['step'] not in('DONE', 'ERROR'):
        op =, op['id'])
>>> op['step']
>>> site_id =, {'name': 'My Site'})[0]['id']

Edit the web site

When the create operation has been done, the site is created, to edit it, retrieve the edition url given in the

>>>, 158)['edit_url']

Manage Virtual Hosts

In order to ship a web site, it must be attached to a virtual host. Every Provider is coming with a domain name to host them in a subdomain. There is few restrictions about the name, but the main one is: the subdomain is unique. first come, first served.

Besides, A site can be attached to many virtual hosts.It’s the vhosts key in this API (see SiteCreate, SiteUpdate, SiteReturn). You can host your web site on gandi domains without DNS modification and with any domain names (see Additional information about security).

Furthermore, the vhosts orders is important to set or retrieve the preferred vhosts. The preferred vhost is used for the SEO and is also retrieved in the SiteListReturn.

Add the virtualhost ‘’ on the previous site.

>>> # add the virtual host to the domain
>>> vhosts = ['', '']
>>> op =, site_id, {'vhosts': vhosts})
>>> ops[0]['type']


It is required to keep the site attach to the Provider domain in order to edit the site.


You must send all virtual hosts. The omitted ones will be deleted.

Upgrade to another offer

>>> # Checkout the prices
>>> prices api.catalog.list(key, {'product': {'type': 'site'}})
>>> # Retrieve list of offers
>>>, {'provider': 'basekit_whitelabel'})

A site can be update to another offer, but cannot be downgraded. It is possible to filter the appropriate “next” offer by using the ‘>name’ filter.

>>> package =, {'provider': 'basekit_whitelabel', '>name': 'personal'})[0]
>>> package
{'name': 'professional', 'provider': 'basekit_whitelabel'}

You can also get the price of this operation.

>>> descr = "{provider}_{name}".format(**package)
>>> api.catalog.list(key, {"product": {"type": "site", "description": descr}, "action": {"name": "update"}})

See the Catalog API for more usage.

The site.update method is free for every usage except the package upgrade.

Delete a site

To delete an instance, use the site.delete() method:

>>> op =, site_id)
>>> op['type']

Additional information about security

If you are not using the Gandi DNS or you did not register your domain at Gandi, you can also run a Site instance hosted at Gandi. Gandi must verify that the domain is your own by checking you have administration privilege on it. To perform that, Gandi will check DNS record on the vhost you want to bind to a site.

>>> site_spec = {
    'name': 'My Site',
    'package': 'professional',
    'vhosts': ['', ''],
    '--dry-run': True}
>>> ops =, site_spec)
[{'attr': ['', 'vhost=2e5d8f0899053fffcd3ecf4ac5a6433b'],
  'field': 'vhosts',
  'field_type': None,
  'reason': 'You must put a TXT value in your zone'}]

The DNS zone must be altered to store the record like:

10800 IN TXT “vhost=2e5d8f0899053fffcd3ecf4ac5a6433b”