def create_heartbeat(): try: heartbeat = Heartbeat.parse_heartbeat(request.data) except ValueError as e: return jsonify(status="error", message=str(e)), 400 if g.get('role', None) != 'admin': heartbeat.customer = g.get('customer', None) try: heartbeat = db.save_heartbeat(heartbeat) except Exception as e: return jsonify(status="error", message=str(e)), 500 body = heartbeat.get_body() body['href'] = absolute_url('/heartbeat/' + heartbeat.id) return jsonify(status="ok", id=heartbeat.id, heartbeat=body), 201, {'Location': body['href']}