forked from ajaykumar127/sfdcmarketingcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·86 lines (79 loc) · 2.2 KB
/
index.js
File metadata and controls
executable file
·86 lines (79 loc) · 2.2 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
74
75
76
77
78
79
80
81
82
83
84
85
86
var express = require('express')
var app = express()
const axios = require('axios');
const CircularJSON = require('circular-json');
var token='';
var weatherData = [];
app.set('port', (process.env.PORT || 5000))
app.use(express.static(__dirname + '/public'))
require('dotenv').load();
app.get('/', function(request, response) {
response.send('Hello World!')
})
app.get('/getweather', function(request, responsefromWeb) {
axios.get('https://api.weather.gov/alerts/active/area/MN')
.then(function (response) {
var datafromCall = response.data.features;
for(var x=0;x<datafromCall.length;x++){
var weatherItem = {
"keys":{
"theid" : datafromCall[x].properties.id
},
"values":{
"field1": datafromCall[x].type,
"field2": datafromCall[x].properties.sender
}
}
weatherData.push(weatherItem);
}
responsefromWeb.send(response.data.features);
})
.catch(function (error) {
console.log(error);
responsefromWeb.send(error);
});
})
app.get('/connecttoMC', function(request, responsefromWeb) {
console.log(process.env.CLIENT_ID);
var conData = {
'clientId': process.env.CLIENT_ID,
'clientSecret': process.env.CLIENT_SECRET
}
axios({
method:'post',
url:'https://auth.exacttargetapis.com/v1/requestToken',
data: conData,
headers:{
'Content-Type': 'application/json',
}
})
.then(function(response) {
responsefromWeb.send('Authorization Sent');
token = response.data.accessToken;
}).catch(function (error) {
console.log(error);
responsefromWeb.send(error);
});
})
app.get('/connecttoMCData', function(request, responsefromWeb) {
axios({
method: 'post',
url: 'https://www.exacttargetapis.com/hub/v1/dataevents/key:testdataextension/rowset',
data: weatherData,
headers:{
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json',
}
})
.then(function(response) {
var json = CircularJSON.stringify(response);
console.log(json);
responsefromWeb.send(json);
})
.catch(function (error) {
console.log(error);
});
})
app.listen(app.get('port'), function() {
console.log("Node app is running at localhost:" + app.get('port'))
})