Created
November 28, 2016 22:31
-
-
Save areski/7433e7d146d4637f03d6fee62a288207 to your computer and use it in GitHub Desktop.
Send SMS via MessageMedia API
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 hmac | |
import hashlib | |
import requests | |
from datetime import datetime | |
utc_str_date = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT") | |
secret = 'SECRET' | |
api_key = "API KEY" | |
url = 'https://rest.messagemedia.com/v1/messages' | |
# content = <HTTP-Verb> + "\n" + <Content-Type> + "\n" + <Date> + "\n" + <RequestPath> + "\n" + <RequestBody> | |
content = "Hello my world!!!" | |
destination_number = "+34650112233" | |
request_body = """ | |
{ | |
"messages": [ | |
{ | |
"content" : "Helloworld!", | |
"destination_number" : "+34650112233" | |
} | |
] | |
} | |
""" | |
content = "POST" + "\n" + "application/json" + "\n" + utc_str_date + "\n" + '/v1/messages' + "\n" + request_body | |
signing = hmac.new(secret, content, hashlib.sha1) | |
# Authorization: MM-1 <API Key> <HMAC> | |
headers = {'Authorization': "MM-1 " + api_key + " " + signing.digest()} | |
# response = requests.get(url, headers=headers) | |
response = requests.post(url, headers=headers, data={'content': 'Helloworld!', 'destination_number': '+34650112233'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment