Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix monobank request errors #11

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mono_actual.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const actualApi = require('@actual-app/api');

const CACHE_DIR_PATH = '.cache/';
const MONO_URL = 'https://api.monobank.ua/';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused 403, luckily easy-fix.

const MONO_URL = 'https://api.monobank.ua';
const DAYS_TO_SYNC = parseInt(process.env.DAYS_TO_SYNC);
const DEFAULT_DAYS_SYNC = DAYS_TO_SYNC < 7 ? DAYS_TO_SYNC : 7;
const MONO_TOKEN = process.env.MONO_TOKEN;
Expand Down Expand Up @@ -89,12 +89,13 @@ async function fetch_data() {

async function fetchMonoData(card, startDateTimestamp, endDateTimestamp) {
try {
const response = await fetch(MONO_URL + '/personal/statement/' + card + '/' + startDateTimestamp + '/' + endDateTimestamp, {
const mono_url = MONO_URL + '/personal/statement/' + card + '/' + startDateTimestamp + '/' + endDateTimestamp;
const response = await fetch(mono_url, {
headers: { 'X-Token': MONO_TOKEN, },
});

if (!response.ok) {
throw new Error('API request failed');
throw new Error(mono_url + ' failed: ' + ' ' + response.status + ' ' + response.statusText);
}

const data = await response.json();
Expand Down
Loading