-
-
Save raykrueger/1592087 to your computer and use it in GitHub Desktop.
SIGNAL HQ API List Creationg Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from pprint import pprint | |
input_data = """<?xml version="1.0" encoding="UTF-8"?><subscription> | |
<subscription-type>EMAIL</subscription-type> | |
<source-keyword>CRAZY_COFFEE</source-keyword> | |
<user> | |
<email-address>[email protected]</email-address> | |
<first-name>Test</first-name> | |
<last-name>User</last-name> | |
<street-address>303 W. Capitol Ave</street-address> | |
<city>Little Rock</city> | |
<state>AR</state> | |
<zip-code>72201</zip-code> | |
<home-phone>501-555-1212</home-phone> | |
</user> | |
</subscription>""" | |
API_KEY = "XXXXXX" | |
CAMPAIGN_ID = 000000 | |
api_call = "https://app.signalhq.com/api/subscription_campaigns/%s/subscriptions.xml" % (CAMPAIGN_ID) | |
headers = {"api_token":API_KEY, | |
"Content-Type":"application/xml"} | |
try: | |
r = requests.post(api_call, headers=headers, data=input_data) | |
print 'REQUEST HEADERS' | |
pprint(r.request.headers) | |
print '***************' | |
print 'REQUEST DATA' | |
pprint(r.request.data) | |
print '***************\n*****************' | |
pprint ("STATUS: %s" % (r.status_code) ) | |
print 'CONFIG' | |
pprint(r.config) | |
print 'ERRORS' | |
print r.error | |
print '*********' | |
print 'HEADERS' | |
pprint(r.headers) | |
print '********' | |
print "CONTENT:" | |
pprint(r.content) | |
except requests.exceptions.ConnectionError: | |
print "Connection Error" | |
except requests.exceptions.HTTPError: | |
print "HTTP Error" | |
except requests.exceptions.Timeout: | |
print "Timeout Error" | |
except requests.exceptions.RequestException: | |
print "Unknown Request Exception" | |
except Exception: | |
print "Unknown Exception" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment