API Examples

Python DNS API code sample

Python Example

The following example code can be used as a framework to build an interface to the Conexim API in Python.

import urllib2 import urllib import hmac import hashlib import base64 import json import pprint import calendar import time import collections secretkey = '19d6a39ee3eccd2df428ae15684202...' keyid = '51f881d6d158f' server = 'https://api.conexim.net' action = '/api/dns/v1/domains/testzonefromapi.net/records' verb = 'POST' params = { 'type': 'A', 'name': 'www', 'value': '123.123.123.123' } params = collections.OrderedDict(sorted(params.items())) utimeGMT = "%d" % calendar.timegm(time.gmtime()) sigString = keyid + '\n' + utimeGMT + '\n' + verb + '\n' + action + '\n' + urllib.urlencode(params) sig = base64.b64encode(hmac.new(key=secretkey, msg=sigString, digestmod=hashlib.sha256).digest()) request = urllib2.Request(server + action, json.dumps(params)) request.add_header('Authorization', 'CONEXIM ' + keyid + ':' + sig) request.add_header('Content-type', 'application/json') request.add_header('Conexim-Time', utimeGMT) request.get_method = lambda: verb try: opener = urllib2.urlopen(request) retdata = json.loads(opener.read()) print "Response Code: " + str(opener.getcode()) print "Contents:" pprint.pprint(retdata) except urllib2.HTTPError, err: print err.read()

PHP Example Ruby Example