-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpRequestBody.js
More file actions
45 lines (40 loc) · 1.21 KB
/
Copy pathhttpRequestBody.js
File metadata and controls
45 lines (40 loc) · 1.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
if (fromVendor) {
const customerId = transformedObject.CustomerID;
const https = require('https');
let options = {
host: "staging.cloud-elements.com",
path: `/elements/api-v2/myOrders?where=${encodeURIComponent(`CustomerID='${customerId}'`)}`,
method: "GET",
"headers": {
"accept": "application/json",
"Authorization": `User ${configuration.userSecret}, Organization ${configuration.organizationSecret}, Element ${configuration.elementInstanceToken}`
}
};
// dataHandling
let data = "";
const request = https.request(options, function(res) {
res.on('data', function(d) {
data += d;
}).on('end', function(d) {
if (res.statusCode === 200) {
let parsedData = JSON.parse(data);
transformedObject.orders = parsedData;
done(transformedObject);
} else {
transformedObject.orders = {
message: "https call to orders failed",
error: res.statusMessage
};
done(transformedObject);
}
});
});
request.on('error', function(e) {
transformedObject.orders = {
message: "https call to orders failed",
error: JSON.stringify(e)
};
done(transformedObject);
});
request.end();
}