Well, I did get it working eventually with a different implementation, namely anvil.server.request.body_json as opposed to anvil.server.request.get_bytes().decode("utf-8"):
@anvil.server.http_endpoint("/send_push_notification", methods=["POST"])
def receive_push_request_api():
"""
API endpoint that allows external apps to send a push notification
"""
try:
request_data = anvil.server.request.body_json
print(request_data)
apartment = request_data.get("apartment")
property = request_data.get("property")
visit_type = request_data.get("visit_type", "default")
delay = request_data.get("delay", 0)
if not apartment or not property:
return {"status": "error", "message": "Missing required parameters."}, 400
# Trigger the existing background task
anvil.server.launch_background_task(
"notify_user_of_package_push", apartment=apartment, property=int(property), visit_type=visit_type, delay=delay
)
return {"status": "success", "message": "Push notification request received."}
except Exception as e:
return {"status": "error", "message": str(e)}, 500
The only problem is that I am not sure why it’s working now, since I believe I tried this method earlier with the same payload and was getting [{"status":"error","message":"'NoneType' object has no attribute 'get'"},500]