Skip to content

Instantly share code, notes, and snippets.

@marccampbell
Created July 28, 2011 21:49
Show Gist options
  • Save marccampbell/1112665 to your computer and use it in GitHub Desktop.
Save marccampbell/1112665 to your computer and use it in GitHub Desktop.
Pager.io API Example: Create Alert
import urllib, urllib2, base64
team_name = 'My Pager.io Team Name'
api_key = 'My Pager.io API Key'
alert_subject = 'Test Alert'
alert_message = 'This is where you would put a longer alert message'
data = {'subject': alert_subject, 'message': alert_message}
base64string = base64.encodestring('%s:%s' % (team_name, api_key)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request('https://pager.io/api/v1/alert', data=urllib.urlencode(data))
request.add_header('Content-Type', 'application/x-www-formurlencoded')
request.get_method = lambda: 'POST'
url = opener.open(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment