Send Push Notification to User Devices - Python

Source Code Option 1: http.client

  

import http.client

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

payload = "api_key=YOUR-API-KEY&user_id=YOUR-CUSTOM-USER-ID&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_by_userid", 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_by_userid"

payload = "api_key=YOUR-API-KEY&user_id=YOUR-CUSTOM-USER-ID&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)