Register User Device - 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=YOUR-PLATFORM&user_id=OPTIONAL-USER-ID&tag=OPTIONAL-TAG"

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

conn.request("POST", "/v1/device/add", 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/device/add"

payload = "api_key=YOUR-API-KEY&device_token=YOUR-DEVICE-TOKEN&platform=YOUR-PLATFORM&user_id=OPTIONAL-USER-ID&tag=OPTIONAL-TAG"
headers = {
    'content-type': "application/x-www-form-urlencoded",
    'cache-control': "no-cache"
    }

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

print(response.text)