-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
61 lines (51 loc) · 2.05 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# import flask framework
from flask import Flask, request
import requests
import json
# create a flask app instance
app = Flask(__name__)
# POST / handler
@app.route('/orca-webhook-out', methods=['POST'])
def webhook_out():
if request.method == 'POST':
data = request.get_json()
# dubug purpose: show in console raw data received
print("Request received: \n"+json.dumps(data, sort_keys=True, indent=4))
# get the name of the action that triggered this request (add, update, delete, test)
action = data["___orca_action"]
# get the name of the sheet this action impacts
sheet_name = data["___orca_sheet_name"]
# get the email of the user who preformed the action (empty if not HTTPS)
user_email = data["___orca_user_email"]
# NOTE:
# orca system fields start with ___
# you can access the value of each field using the field name (data["Name"], data["Barcode"], data["Location"])
if action == "add":
# TODO: do something when a row has been added
pass
elif action == "update":
# TODO: do something when a row has been updated
pass
elif action == "delete":
# TODO: do something when a row has been deleted
pass
elif action == "test":
# TODO: do something when the user in the web app hits the test button
pass
# always return a 200 (ok)
return "ok"
# Trigger Webhook In
@app.route('/trigger-webhook-in', methods=['GET'])
def trigger_webhook_in():
# the following example adds a new row to a sheet, setting the value of Barcode, Name, Quantity and Description
# TODO: change url to https://api.orcascan.com/sheets/{id}
response = requests.post('https://httpbin.org/post', json={
"___orca_action": "add",
"Barcode": "0123456712",
"Name": "New 1",
"Quantity": 12,
"Description": "Add new row example"
})
if response.ok:
print(response.content)
return "ok"