Repository navigation
Expand file tree
/
Copy pathrestAPI.js
More file actions
61 lines (52 loc) · 1.67 KB
/
Copy pathrestAPI.js
File metadata and controls
61 lines (52 loc) · 1.67 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
const express = require("express");
const bodyParser = require("body-parser");
const Axios = require("axios");
const App = express();
let accessToken = "";
let dealData = { TITLE: "" };
App.use(bodyParser.json());
App.use(bodyParser.urlencoded({ extended: true }));
App.set("view engine", "ejs");
//Index page , this will help to login to Bitrix (checkout the views/index.ejs and update the client ID to your Bitrix URL)
App.get("/", (req, res) => {
res.render("index");
});
//Deals get page for getting the auth token.
//Update the Client ID , Client secret to your Bitrix application
App.get("/deals", (req, res) => {
if (req.query.code) {
Axios.post(
`https://oauth.bitrix.info/oauth/token/?client_id=local.5d57eb432701c8.48502774&grant_type=authorization_code&client_secret=dhSK2BQ1dqCsbJPc6TqGJy2RTOUsjLt8TSRPD1UhpdDRQyhDMO&code=${
req.query.code
}&scope=user,task`
)
.then(res => {
accessToken = res.data.access_token;
console.log(res.data);
})
.catch(err => {
console.log(err);
});
}
res.render("deals", { data: dealData });
});
//Get the data from Bitrix for individual deal
App.post("/deals", (req, response) => {
console.log(req.body, accessToken);
Axios.post(
`https://staging.allcadservices.com/rest/crm.deal.get?auth=${accessToken}`,
{ id: req.body.dealid }
)
.then(res => {
console.log(res);
dealData = res.data.result;
response.render("deals", { data: dealData });
})
.catch(err => {
console.log(err);
});
});
//Update to your Servers IP address
App.listen("3000", "192.168.2.18", function() {
console.log("server started on port 3000");
});