forked from jackmatt2/koinly-csv-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_testCookies.js
61 lines (55 loc) · 2.23 KB
/
test_testCookies.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
60
61
(function(input) {
var PAGE_COUNT = 25;
var getCookie = (name) => {
const cookies = document.cookie.split('; ');
const cookieMap = cookies.map(it => it.split('='))
.reduce((prev, curr) => {
const [key, value] = curr;
return {
...prev,
[key]: value,
}
}, {})
return cookieMap[name]
}
var fetchHeaders = (api_key, portfolio_id, cookie) => {
const headers = new Headers();
headers.append('authority', 'api.koinly.io');
headers.append('accept', 'application/json, text/plain, */*');
headers.append('accept-language', 'en-GB,en-US;q=0.9,en;q=0.8');
headers.append('access-control-allow-credentials', 'true');
headers.append('caches-requests', '1');
headers.append('cookie', cookie);
headers.append('origin', 'https://app.koinly.io');
headers.append('referer', 'https://app.koinly.io/');
headers.append('sec-fetch-dest', 'empty');
headers.append('sec-fetch-mode', 'cors');
headers.append('sec-fetch-site', 'same-site');
headers.append('sec-gpc', '1');
headers.append('user-agent', navigator.userAgent);
headers.append('x-auth-token', api_key);
headers.append('x-portfolio-token', portfolio_id);
return headers;
}
var fetchSession = async (api_key, portfolio_id, cookie) => {
const requestOptions = {
method: 'GET',
headers: fetchHeaders(api_key, portfolio_id, cookie),
redirect: 'follow'
};
try {
const response = await fetch('https://api.koinly.io/api/sessions', requestOptions);
return response.json();
} catch(err) {
console.error(err)
throw new Error('Fetch session failed')
}
}
var run = async (api_key, portfolio_id, cookie) => {
console.log(api_key + ' ' + portfolio_id + ' ' + cookie)
var session = await fetchSession(api_key, portfolio_id, cookie)
var baseCurrency = session.portfolios[0].base_currency.symbol;
console.log(session);
}
run(input.api_key, input.portfolio_id, input.cookie);
})(obj)