-
Notifications
You must be signed in to change notification settings - Fork 0
/
torizon_api.js
37 lines (34 loc) · 1.07 KB
/
torizon_api.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
const axios = require('axios');
require('dotenv').config();
//Add your API Bearer token here
const api_bearer_token = process.env.TORIZON_API_TOKEN;
const torizon_api = axios.create({
baseURL: 'https://app.torizon.io/api/v2beta',
headers: {
"Content-type": "application/json",
"Authorization": "Bearer " + api_bearer_token
}
});
/**
* Makes an Authorization "Bearer" request with the given accessToken to the given endpoint.
* @param endpoint torizon API endpoint
* @param method HTTP method
* @param data data to be sent in the request
*/
const requestTorizonAPI = async (endpoint, data = null, method = 'GET') => {
switch (method) {
case 'GET':
return torizon_api.get(endpoint);
case 'POST':
return torizon_api.post(endpoint, JSON.stringify(data));
case 'DELETE':
return torizon_api.delete(endpoint + `/${data}`);
case 'PUT':
return torizon_api.put(endpoint + `/${data}`);
default:
return null;
}
};
module.exports = {
requestTorizonAPI,
};