Sending Data to Exosite with the HTTP API

Exosite’s HTTP API has been mentioned in some of our previous posts, but we wanted to call attention to it. This is one of the simplest ways to send data to Exosite, especially for Internet-connected devices with scripting capability. The API requires an HTTP POST request in this format:

POST /api:v1/stack/alias HTTP/1.1
Host: m2.exosite.com
X-Exosite-CIK: INSERT_YOUR_CIK
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: INSERT_LENGTH_OF_POST_DATA

RESOURCE_ID1=VALUE&RESOURCE_ID2=VALUE

Remember to replace the PLACEHOLDER_TEXT with actual values. The perfect device to test this API is your very own computer. If you have Python, simply copy the code below, input your own CIK/resource IDs/values, and then run it.

"""
test app for Exosite HTTP Basic Post API
"""
import urllib
import httplib
url = '/api:v1/stack/alias'
params = urllib.urlencode({'RESOURCE_ID1': VALUE, 'RESOURCE_ID2': VALUE})
headers = {'X-Exosite-CIK': 'INSERT_YOUR_CIK', 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}

conn = httplib.HTTPConnection('m2.exosite.com')
conn.request("POST",url,params,headers)
response = conn.getresponse();
print 'response: ',response.status,response.reason
data = response.read()
end = data.find('<')
if -1 == end: end = len(data)
print data[:end]

conn.close()

If you don’t have Python, stop what you are doing and download it now! Python is an awesome programming language, and one we use frequently here at Exosite.

Check out the Exosite API documentation for complete API details.

This entry was posted in Projects and tagged , . Bookmark the permalink.

Comments are closed.