Slicehost API: April 1, 2008
Slicehost API: April 1, 2008
Version 1.2
April 1, 2008
Introduction 3
Getting Started
3
Authentication
3
ActiveResource 3
Ruby Example 4
Python Example 5
Services
7
DNS
7
Zone
7
Record 7
Common Errors 8
Introduction
To use the Slicehost API, you must have a Slicehost account. You may enable or
disable API access from this account, and you may re-generate your API password as
you see fit.
This API follows a standard ActiveResource pattern as seen in Ruby on Rails. The
examples in this document are in Ruby, using the Ruby on Rails ActiveResource library.
Getting Started
Authentication
Before you can access the API service, you must enable the service in the
SliceManager under the Account tab. Note that this automatically generates a unique
API password for you. Should you need to update the password, you can generate a
new one from the same page at any time.
Authentication for the API uses standard HTTP Authentication which uses your unique
password as part of the URL.
Hereʼs an example:
https://[email protected]/
ActiveResource
To learn about how to use ActiveResource within Ruby (or to develop a way to do it in
another language, we suggest reading the ActiveResource README.
require 'activeresource'
API_PASSWORD = "3da541559918a808c2402bba5012f6c60b27661c"
myzone = nil
myzone = Zone.find(zid) # Retrieving the same Zone we just created
myzone.ttl = 8000
myzone.save # Updating the TTL
Since Python has no ActiveResource library available (yet), we have to build an HTTP
request ourselves. We put together a simple APIRequest object to do just that. For more
information on whatʼs going on, read through the link in the ActiveResource section.
(There is also a beta library called pyactiveresource written by our own Jared Kuolt
which you can use as an alternative to the method below.)
import httplib
import urllib
import base64
class APIRequest(object):
if id:
self.path = '/%s/%s.xml' % (self.object_type_plural, id)
else:
self.path = '/%s.xml' % self.object_type_plural
return urllib.urlencode(np)
def response(self):
conn = httplib.HTTPSConnection(self.host)
conn.request(self.method, self.path, self.params,
self.headers)
return conn.getresponse().read()
def main():
pw = 'my-api-password'
# Destroying a Zone
APIRequest(pw, 'zone', id=zone_id, method='DELETE').response()
if __name__ == '__main__':
main()
Note: In addition to all fields outlined below, the `id` field is the identifier of an object
which may not be changed.
DNS
DNS is split into two sets of resources: Zones and Records. Zones represent a domain,
whereas Records represent the records within a Zone.
Zone
Record