-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (31 loc) · 2.02 KB
/
test.js
File metadata and controls
36 lines (31 loc) · 2.02 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
import express from 'express';
import axios from 'axios';
import qs from 'qs';
import fs from 'fs'
import session from 'express-session';
import dotenv from 'dotenv';
dotenv.config();
const token = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI5ZGY3MmNmNC02ZDc0LTQwZjItODU0My00OTllZGY1MmEyNGQiLCJqdGkiOiI3YWQ0ZTkzZmY1M2JjYzc4MGY2YTc2ZmVmYWUxZWZhOGRlYzY0MGQ0YzBlZWMyOWE1NDQ3NmI0NDhlNmY5NmEzOTNiMWY3ZjI0MzNiZmNhYiIsImlhdCI6MTczOTU1NTA1OS42MTI5NTUsIm5iZiI6MTczOTU1NTA1OS42MTI5NTcsImV4cCI6MTc3MTA5MTA1OS42MDEyMzksInN1YiI6IjExMzkiLCJzY29wZXMiOltdfQ.P3lvI0R-kzVQj2qcfcmrSIjDqhzvVZW7g_SQmU3Gk-eREJYDIoZOKbfrP3cDfRFo1QxQdVIPVl8c3oyGjf2CbTk17o10bl9E7zeAIkb_erBe39ZO_6Kol5a8BQiNvHFZisfsdxU1rRdxiNUBDLqqprQKEtDfuGD-Hh_G4XBUPa9KMAwcM99TXCu2NI8kIE_DIJwG463CCkR6bONbrTr_oDAQu-jsi6bz6sGlWfWgBZmAsmjUP9fpGrrlLADXR_dZf5Koi6E9TkDKDVeI8GjdZnxe0zgu-fNJ5KoHHMtEunitgNMFoi6_jdkbG3johPmEhUGMAP8-qPrKVBjqQVUZp2YWoxa1gZ92aLgl1UiQ_HbgcmXSR8Uves0VAcopfi_dhzc60W97gn4TMEREaYX1F_Tp8UG5FHXrqbTrXbscA_c1bMV8VS8lleLydeWpcpDfXeAd1yCGPYo_WT7FEKNYJyz3a3uUQ9p8lIACEBzhc94G_DKDu4MlspBq9ItoZI2nTEmYYnkbhVd7cji7hkMKCUiLWGOegAKl0DBPhavi22mlP5ob_LFvvfyseD5LxZJv1nJzpIdmRDJoIkLMzMBDq88nM06Ks3OR7ptPNGl0o3030eg-yCpJEen_j1L6kxUGGHSpWLlkovqqzm5WdqkhcHeVymBhaHUlsZBSS0VHccc";
const callAPI = (url = 'treatment-types') => {
let api_url = process.env.API_URL + '/' + url;
console.log(api_url);
axios.get(api_url, {
headers: {
'Accept': 'application/json',
'Authorization': token // Assuming token is stored in environment variable
}
}).then(res => {
console.log(res.data.data);
const data = res.data;
fs.writeFile(`./data/test-${url}.json`, JSON.stringify(data.data, null, 2), (err) => {
if (err) {
console.error('Failed to write to file:', err);
} else {
console.log(`Data successfully written to test-${url}.json`);
}
});
}).catch(error => {
console.error('API call failed:', error);
});
}
callAPI();