Skip to content

Instantly share code, notes, and snippets.

@TylerMills
Last active February 5, 2016 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylerMills/b65348e2272ad88f2515 to your computer and use it in GitHub Desktop.
Save TylerMills/b65348e2272ad88f2515 to your computer and use it in GitHub Desktop.
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