-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab04.main.js
59 lines (49 loc) · 1.88 KB
/
lab04.main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Update this constant with your ServiceNow credentials
const options = {
url: 'https://dev50714.service-now.com/',
username: 'admin',
password: '9w*6hPP$R82k6hP#Vd#mMjYca5vyjrdm',
serviceNowTable: 'change_request'
};
/**
* Import the Node.js request package.
* See https://www.npmjs.com/package/request
*/
//const request = require('request');
// We'll use this regular expression to verify REST API's HTTP response status code.
//const validResponseRegex = /(2\d\d)/;
// Import built-in Node.js package path.
const path = require('path');
/**
* Import the ServiceNowConnector class from local Node.js module connector.js.
* and assign it to constant ServiceNowConnector.
* When importing local modules, IAP requires an absolute file reference.
* Built-in module path's join method constructs the absolute filename.
*/
const ServiceNowConnector = require(path.join(__dirname, './connector.js'));
/**
* @function mainOnObject
* @description Instantiates an object from the imported ServiceNowConnector class
* and tests the object's get and post methods.
*/
function mainOnObject() {
// Instantiate an object from class ServiceNowConnector.
const connector = new ServiceNowConnector(options);
// Test the object's get and post methods.
// You must write the arguments for get and post.
connector.get((data, error) => {
if (error) {
console.error(`\nError returned from GET request:\n${JSON.stringify(error)}`);
}
console.log(`\nResponse returned from GET request:\n${JSON.stringify(data)}`)
});
// connector.post();
connector.post({}, (data, error) => {
if (error) {
console.error(`\nError returned from POST request:\n${JSON.stringify(error)}`);
}
console.log(`\nResponse returned from POST request:\n${JSON.stringify(data)}`)
});
}
// Call mainOnObject to run it.
mainOnObject();