Use the Alta Video POS API to test POS webhooks
Last modified: Monday January 08, 2024.
Review the example Python script that allows testing of the webhooks used to communicate between the point-of-sale (POS) device and your Alta Video deployment.
Example python script
Test webhooks
import requests,json,time
from datetime import datetime
#Post messages to the defined webhook, using secret and register id.__
# These are stored in a register object along with a session.
# Using a session reduces the overhead of setting up and tearing down connections.
class AwarePOSRegister:
def __init__(self,webhook,secret,registerid):
self.webhook=webhook
self.headers={'Authorization': 'Bearer '+ secret}
self.registerid=registerid
self.session=requests.session()
self.id = 0
### Methods for sending webhooks.
def sendItem(self,item,value,currency):
# Send a single item, note multiple could be sent in one message.
dtnow=datetime.now()
self.id +=1
data={"type":"data","id":str(self.id),"register_id":self.registerid,
"messages":[{"timestamp":int(dtnow.timestamp()*1000),
"msg_id":str(dtnow.timestamp()),
"data":item,
"value":value,
"currency":currency}]}
response=self.session.post(self.webhook,json=data,headers=self.headers)
return(response)
def sendKeepalive(self):
# send a keepalive, should be done every 30 seconds
self.id +=1
data={"type":"keepalive","id":str(self.id),"register_id":self.registerid}
response=self.session.post(self.webhook,json=data,headers=self.headers)
return(response)
server="https://<deployment_name>.<region>.aware.avasecurity.com"
webhook="<webhook_GUID>"
secret="<secret>"
## Not the id from Alta Video, but the external_id
registerid="<external_id>"
webhook=server+"/api/v1/public/pos/"+webhook+"/http"
#Create the register object
awareReg=AwarePOSRegister(webhook,secret,registerid)
# Send some test items.
resp=awareReg.sendItem("Shoes","12.34","GBP")
print(resp.status_code)
time.sleep(1)
resp=awareReg.sendItem("Coffee","56.78","GBP")
time.sleep(1)
resp=awareReg.sendItem("Discount %","10","%")
resp=awareReg.sendItem("Discount","6.91","GBP")
resp=awareReg.sendItem("Total","62.21","GBP")
# Periodic keep alives should be sent.
# This could be done from a separate thread, with a timer.
resp=awareReg.sendKeepalive()