This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathsnow.js
More file actions
executable file
·58 lines (52 loc) · 1.82 KB
/
snow.js
File metadata and controls
executable file
·58 lines (52 loc) · 1.82 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
module.exports = function (app) {
var request = require('request'); //npm install request
var bodyParser = require('body-parser') //npm install --save body-parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
var baseRequest = request.defaults({
baseUrl: 'https://nowforumlondonapidemo.service-now.com',
auth: {
'user': 'xxxxxx',
'pass': 'xxxxxxx',
'sendImmediately': true
}
})
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
return body;
} else {
console.log('Error from SNOW: ' + error);
console.log('Error from SNOW: ' + JSON.stringify(body));
return body;
}
}
// Register Phone numbers
app.post('/register', function (req, res) {
// Get Phone number
var from = req.body.From;
if (!from) {
return res.sendStatus(400);
}
var postBody = {
u_phone_num: from
}
baseRequest({
method: 'post',
uri: '/api/now/import/u_attendee_phone_number_imp_ws',
json: true,
body: postBody
}, function (error, response, body) {
res.append('Content-Type','text/xml');
body = '<?xml version="1.0" encoding="UTF-8"?><Response><Message>Thank you for registering. For demo source and docs check http://goo.gl/d9X9XH</Message></Response>';
res.send(body);
});
})
// Retrieve registered Phone numbers
app.get('/phoneList', function (req, res) {
baseRequest('/api/now/stats/u_session_attendees?sysparm_count=true', function (error, response, body) {
res.send(callback(error, response, body));
});
})
}