Skip to content

Instantly share code, notes, and snippets.

@weezqyd
Last active May 16, 2020 12:47
Show Gist options
  • Save weezqyd/29a1f563931417e2ebeba86e71a31d28 to your computer and use it in GitHub Desktop.
Save weezqyd/29a1f563931417e2ebeba86e71a31d28 to your computer and use it in GitHub Desktop.
import pprint
import requests
def get_token():
url = 'https://api.emalify.com/v1/oauth/token'
payload = {
"client_id": "client_id",
"client_secret": "client_secret",
"grant_type": "client_credentials"
}
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
response = requests.request('POST', url, headers=headers, json=payload, allow_redirects=False)
return response.json()["access_token"]
def send_message():
url = "https://api.emalify.com/v1/projects/PROJECT_ID/sms/simple/send"
payload = {
"to": [254729422001],
"message": "Test sender from Emalify API proxy",
"messageId": "f429eb246684581a7c4faefbfa807b67db58ec58",
"callback": "https://webhook.site/e83c90d0-d168-4337-82ca-e8543c1b0d44",
"from": "Emalify"
}
headers = {
'Accept': "application/json",
'Content-Type': "application/json",
'Authorization': f"Bearer {get_token()}",
}
response = requests.request("POST", url, json=payload, headers=headers)
return response.text
pprint.pprint(send_message())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment