Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Python code to access the StatsMix API
# send a new stat to a metric
import httplib
import urllib
params = urllib.urlencode({'metric_id': XXXXX, 'value': 1})
# generated_at is set to now by default, to explicitly set use the following:
# params = urllib.urlencode({'metric_id': 4877, 'value': 1, 'generated_at':'2012-07-08 12:33:53'})
headers = {'X-StatsMix-Token': 'STATSMIX_API_KEY'}
conn = httplib.HTTPConnection('api.statsmix.com:80')
conn.request('POST', '/api/v2/stats', params, headers)
response = conn.getresponse()
print response.status, response.reason
print response.read()
conn.close()
# send a new stat to a metric using the track method
# unles a profile_id is explicity set, the metric will be added to the first profile in the account
import httplib
import urllib
params = urllib.urlencode({'name': 'Python Test Metric', 'value': 1})
headers = {'X-StatsMix-Token': 'STATSMIX_API_KEY'}
conn = httplib.HTTPConnection('api.statsmix.com:80')
conn.request('POST', '/api/v2/track', params, headers)
response = conn.getresponse()
print response.status, response.reason
print response.read()
conn.close()
# delete a stat from a metric
params = None
headers = {'X-StatsMix-Token': 'STATSMIX_API_KEY'}
stat_id = XXXXX
conn = httplib.HTTPConnection('api.statsmix.com:80')
conn.request('DELETE', '/api/v2/stats/%d/' % stat_id, params, headers)
response = conn.getresponse()
print response.status, response.reason
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.