Send Direct Push Notification - Python

Source Code Option 1: http.client

  
                         
import http.client

conn = http.client.HTTPSConnection("send.pushnotificationapi.com")

payload = "api_key=YOUR-API-KEY&device_token=YOUR-DEVICE-TOKEN&platform=iOS&msg_title=test%20message&destination_url=https%3A%2F%2Fpushnotificationapi.com"

headers = {
    'content-type': "application/x-www-form-urlencoded",
    'cache-control': "no-cache"
    }

conn.request("POST", "/v1/push/send_direct", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

 

Source Code Option 2: requests

  
                         
import requests

url = "https://send.pushnotificationapi.com/v1/push/send_direct"

payload = "api_key=YOUR-API-KEY&device_token=YOUR-DEVICE-TOKEN&platform=iOS&msg_title=test%20message&destination_url=https%3A%2F%2Fpushnotificationapi.com"
headers = {
    'content-type': "application/x-www-form-urlencoded",
    'cache-control': "no-cache"
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)