-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathnode-calls.js
42 lines (34 loc) · 908 Bytes
/
node-calls.js
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
const https = require('https')
const username = '<API Username>'
const password = '<API Password>'
const postFields = {
from: "+46723175800",
to: "+46723175800",
voice_start: '{"connect":"+461890510"}'
}
const key = Buffer.from(username + ':' + password).toString("base64");
const querystring = new URLSearchParams(postFields)
const postData = querystring.toString()
const options = {
hostname: 'api.46elks.com',
path: '/a1/Calls',
method: 'POST',
headers: {
'Authorization': 'Basic ' + key
}
}
const callback = (response) => {
var str = ''
response.on('data', (chunk) => {
str += chunk
})
response.on('end', () => {
console.log(str)
})
}
// Start the web request.
const request = https.request(options, callback)
// Send the real data away to the server.
request.write(postData)
// Finish sending the request.
request.end()