Performing API Calls

Sample API pseudo-call

API Request

The following pseudo code represents how a typical request is formulated and made:

//The Key Identifier
$keyId = “51f881d6d158f”

//The Key Shared Secret
$keyData = “19d6a39ee3edf428ae156842026241bc7c20f5c793946d9e9...”
$baseURL = “https://api.conexim.net”

//API call to be made
$action = “/api/dns/v1/domains/testzone.tld”
//Verb (GET/POST/PUT/DELETE)
$verb = ”GET”

//Encode all parameters as a key/value JSON request
$jsonRequest = { “param1”: “val1”,
                 “param2”: “val2” }
//Generate the signed data. Parameters must be pre-sorted
$sigString = $keyId+“n”+
		 $time + “n” +
		 $verb + “n” +
 $action + “n” +
 “param1=val1&param2=val2”

//Generate a signature for the request
$signedString = base64_encode(hash_hmac(“SHA256”, $sigString, $keyData))
$httpObject = new HTTPRequestObject()

//Set the Content-type header to application/json 
$httpObject.Headers[‘Content-type’] = ‘application/json’
$httpObject.Headers[‘Conexim-Time’] = $time
//Set the request method as either GET, POST, DELETE or PUT
$httpObject.Method = $verb

//Set the post fields as a JSON request
$httpObject.PostData = $jsonRequest
//Execute the request and retrieve the response as JSON
$resultSet = $httpObject.execute()

Data returned by a successful API call (HTTP response code 200) is returned as JSON data. Responses other than 200 are basic HTML errors messages.


Authentication PHP Example