-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
79 lines (68 loc) · 1.85 KB
/
index.js
File metadata and controls
79 lines (68 loc) · 1.85 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
const express = require("express");
const axios = require("axios");
const app = express();
const api1 =
"https://customer-analytics-34146.my.salesforce-sites.com/services/apexrest/createAccount";
const api2 =
"https://customer-analytics-34146.my.salesforce-sites.com/services/apexrest/buyStocks";
function createAccount() {
// • Method: POST
// • Headers:
// o Content-Type: application/json
// • Body: JSON
// {
// "name": "Your Full Name", (string)
// "email": "your_colle@example.com", (string)
// "rollNumber": Your roll Number, (number)
// "phone": Your Phone Number (number)
// }
const config = {
headers: {
"Content-Type": "application/json",
},
};
const data = {
name: "Harshit Jindal",
email: "harshit0575.be21@chitkara.edu.in",
rollNumber: 2110990575,
phone: 9781596878,
};
axios
.post(api1, data, config)
.then((response) => {
console.log(response.data);
console.log("Account created");
const accountNumber = response.data.accountNumber;
console.log({ accountNumber });
buyStocks(accountNumber);
})
.catch((err) => {
console.log(err.message);
console.log("API 1 error");
});
}
function buyStocks(accountNumber) {
const config = {
headers: {
"Content-Type": "application/json",
"bfhl-auth": 2110990575,
},
};
const data = {
company: "Bajaj Finance Ltd",
currentPrice: 6544.2,
accountNumber,
githubRepoLink: "https://github.com/harshit6878/Bajaj.git",
};
axios
.post(api2, data, config)
.then((response) => {
console.log("Stocks bought");
console.log(response.data);
})
.catch((err) => {
console.log("Couldn't buy stocks");
console.log(err.message);
});
}
createAccount();