Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
73 lines (58 loc) · 2.21 KB
/
Copy pathserver.js
File metadata and controls
73 lines (58 loc) · 2.21 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
const express = require('express');
const axios = require('axios');
const app = express();
// Parse JSON bodies for this app.
app.use(express.json());
app.post('/orca-webhook-out', function(request, response) {
data = request.body;
// debug purpose: show in console raw data received
console.log("Request received: \n"+JSON.stringify(data, null, 2));
// get the name of the action that triggered this request (add, update, delete, test)
const eventName = data.___orca_event;
// get the name of the sheet this action impacts
const sheetName = data.___orca_sheet_name;
// get the email of the user who preformed the action (empty if not HTTPS)
const userEmail = 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)
switch (eventName) {
case "rows:add": {
// TODO: do something when a row has been added
} break;
case "rows:update": {
// TODO: do something when a row has been updated
} break;
case "rows:delete": {
// TODO: do something when a row has been deleted
} break;
case "test": {
// TODO: do something when the user in the web app hits the test button
} break;
}
response.sendStatus(200);
});
app.get('/trigger-webhook-in', async function(request, response){
// The following example adds a new row to a sheet, setting the value of Barcode, Name, Quantity and Description
const json = JSON.stringify(
{
"___orca_action": "add",
"Barcode": "0123456789",
"Name": "New 1",
"Quantity": 12,
"Description": "Add new row example"
}
);
// TODO: change url to https://api.orcascan.com/sheets/{id}
const res = await axios.post("https://httpbin.org/post", json, {
headers: {
// Overwrite Axios's automatically set Content-Type
'Content-Type': 'application/json'
}
});
console.log(res.statusText);
response.sendStatus(200);
});
app.listen(8888, function() {
console.log('Example app is listening on port 8080.');
});