Last active
February 5, 2016 20:15
-
-
Save TylerMills/b65348e2272ad88f2515 to your computer and use it in GitHub Desktop.
This file contains 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 | |
import json | |
import uuid | |
APP_KEY = 'APP_KEY_HERE' # settings -> apps in localytics dashboard | |
API_KEY = 'API_KEY_HERE' # settings -> API keys localytics dashboard | |
API_SECRET = 'API_SECRET_HERE' # settings -> API keys localytics dashboard | |
headers = {'content-type': 'application/json'} | |
endpoint = 'https://messaging.localytics.com/v2/push/' + APP_KEY | |
request = uuid.uuid4() # not required to include this field but necessary for troubleshooting | |
profile = { | |
"profile":{ | |
"criteria":[ | |
{ | |
"key":"Political Party", | |
"scope":"LocalyticsOrganization", | |
"type":"string", | |
"op":"in", | |
"values":["Libertarian"]}, | |
{ | |
"key":"Gender", | |
"scope":"LocalyticsOrganization", | |
"type":"string", | |
"op":"in", | |
"values":["Male, Other"] | |
} | |
], "op":"and"} | |
} | |
message = 'Vote for John Smith 2024!' # modify to appropriate message | |
payload = { | |
"request_id": request, | |
"campaign_key": "2024 Libertarian Election Promotion", | |
"target_type": "profile", | |
"messages": [ | |
{ | |
"target" : profile, | |
"alert": message | |
} | |
] | |
} | |
push = requests.post(endpoint, json.dumps(payload), auth=(API_KEY, API_SECRET), headers=headers) | |
print(push.status_code) | |
print(push.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment