[GH-ISSUE #1120] [Bug]: API Cannot read properties of null (reading 'timestamp') #7371

Closed
opened 2026-04-10 17:09:54 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @bryce-hoehn on GitHub (Jun 11, 2023).
Original GitHub issue: https://github.com/actualbudget/actual/issues/1120

Verified issue does not already exist?

  • I have searched and found no existing issue

What happened?

I'm trying to write a script to import my bank transactions into actual. Here is what I have so far (password / url / etc removed obviously):

let api = require('@actual-app/api');

(async () => {
  await api.init({
    // Budget data will be cached locally here, in subdirectories for each file.
    dataDir: './actual',
    // This is the URL of your running server
    serverURL: {url},
    // This is the password you use to log into the server
    password: {password},
  });


  await api.importTransactions({account-id}, [
  {
    account_id: {account-id},
    date: "2023-06-10",
    amount: 1,
    payee: "test"
  },
]);
  await api.shutdown();
})();

I am running Actual v23.6.0 in docker. I don't have much experience with Node so it's possibly a user error, but I followed all the documentation for installing the API via npm.

What error did you receive?

/data/node_modules/@actual-app/api/dist/app/bundle.api.js:49072

                        let latestTimestamp = Object(_crdt__WEBPACK_IMPORTED_MODULE_10__["getClock"])().timestamp.toString();
                                                                                                       ^

TypeError: Cannot read properties of null (reading 'timestamp')
    at Object.undoDisabled (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:49072:104)
    at _runMutator (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:59965:24)
    at run (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:64483:45)
    at sequenceState.queue.push.resolve.resolve (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:64498:36)
    at new Promise (<anonymous>)
    at /data/node_modules/@actual-app/api/dist/app/bundle.api.js:64497:32
    at /data/node_modules/@actual-app/api/dist/app/bundle.api.js:49071:89
    at runHandler (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:59948:31)
    at Object.send (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:59597:98)
    at send (/data/node_modules/@actual-app/api/dist/methods.js:34:21)

Where are you hosting Actual?

Docker

What browsers are you seeing the problem on?

Firefox

Operating System

Linux

Originally created by @bryce-hoehn on GitHub (Jun 11, 2023). Original GitHub issue: https://github.com/actualbudget/actual/issues/1120 ### Verified issue does not already exist? - [X] I have searched and found no existing issue ### What happened? I'm trying to write a script to import my bank transactions into actual. Here is what I have so far (password / url / etc removed obviously): ``` let api = require('@actual-app/api'); (async () => { await api.init({ // Budget data will be cached locally here, in subdirectories for each file. dataDir: './actual', // This is the URL of your running server serverURL: {url}, // This is the password you use to log into the server password: {password}, }); await api.importTransactions({account-id}, [ { account_id: {account-id}, date: "2023-06-10", amount: 1, payee: "test" }, ]); await api.shutdown(); })(); ``` I am running Actual v23.6.0 in docker. I don't have much experience with Node so it's possibly a user error, but I followed all the documentation for installing the API via npm. ### What error did you receive? ``` /data/node_modules/@actual-app/api/dist/app/bundle.api.js:49072 let latestTimestamp = Object(_crdt__WEBPACK_IMPORTED_MODULE_10__["getClock"])().timestamp.toString(); ^ TypeError: Cannot read properties of null (reading 'timestamp') at Object.undoDisabled (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:49072:104) at _runMutator (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:59965:24) at run (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:64483:45) at sequenceState.queue.push.resolve.resolve (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:64498:36) at new Promise (<anonymous>) at /data/node_modules/@actual-app/api/dist/app/bundle.api.js:64497:32 at /data/node_modules/@actual-app/api/dist/app/bundle.api.js:49071:89 at runHandler (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:59948:31) at Object.send (/data/node_modules/@actual-app/api/dist/app/bundle.api.js:59597:98) at send (/data/node_modules/@actual-app/api/dist/methods.js:34:21) ``` ### Where are you hosting Actual? Docker ### What browsers are you seeing the problem on? Firefox ### Operating System Linux
GiteaMirror added the bugneeds infoAPI labels 2026-04-10 17:09:54 -05:00
Author
Owner

@j-f1 commented on GitHub (Jun 11, 2023):

I don‘t think it’s been released yet but we recently merged https://github.com/actualbudget/actual/pull/1073 which would give you a more sensible error message in this case. Specifically, you’ll need to download/open a budget first before you can import transactions into it. Does that fix your issue?

<!-- gh-comment-id:1586362323 --> @j-f1 commented on GitHub (Jun 11, 2023): I don‘t think it’s been released yet but we recently merged https://github.com/actualbudget/actual/pull/1073 which would give you a more sensible error message in this case. Specifically, you’ll need to download/open a budget first before you can import transactions into it. Does that fix your issue?
Author
Owner

@bryce-hoehn commented on GitHub (Jun 11, 2023):

That makes sense, I've adjusted my code to include the budget downloading line from the example documentation but am now getting a different error.

New code:

let api = require('@actual-app/api');

(async () => {
  await api.init({
    // Budget data will be cached locally here, in subdirectories for each file.
    dataDir: './actual',
    // This is the URL of your running server
    serverURL: {url},
    // This is the password you use to log into the server
    password: {password},
  });

  await api.downloadBudget({sync-id});

  await api.importTransactions({account-id}', [
  {
    account_id: "{account-id}",
    date: "2023-06-11",
    amount: 1,
    payee: "test"
  },
]);
  await api.shutdown();
})();

New error message:

                    let file = files.find(f => f.groupId === syncId);
                                     ^

TypeError: Cannot read properties of null (reading 'find')
    at module.exports../packages/loot-core/src/server/api.ts.handlers.api/download-budget (/home/bryce/node_modules/@actual-app/api/dist/app/bundle.api.js:49186:38)

<!-- gh-comment-id:1586367124 --> @bryce-hoehn commented on GitHub (Jun 11, 2023): That makes sense, I've adjusted my code to include the budget downloading line from the example documentation but am now getting a different error. New code: ``` let api = require('@actual-app/api'); (async () => { await api.init({ // Budget data will be cached locally here, in subdirectories for each file. dataDir: './actual', // This is the URL of your running server serverURL: {url}, // This is the password you use to log into the server password: {password}, }); await api.downloadBudget({sync-id}); await api.importTransactions({account-id}', [ { account_id: "{account-id}", date: "2023-06-11", amount: 1, payee: "test" }, ]); await api.shutdown(); })(); ``` New error message: ``` let file = files.find(f => f.groupId === syncId); ^ TypeError: Cannot read properties of null (reading 'find') at module.exports../packages/loot-core/src/server/api.ts.handlers.api/download-budget (/home/bryce/node_modules/@actual-app/api/dist/app/bundle.api.js:49186:38) ```
Author
Owner

@j-f1 commented on GitHub (Jun 11, 2023):

Can you download the beta API build here? (from this build). Once you’ve downloaded that zip, uncompress it to get a tgz file. Then pass that to npm install /path/to/actual-api.tgz to install it into your project. Can you try again and let me know what error you get (please send the full error log)?

<!-- gh-comment-id:1586373713 --> @j-f1 commented on GitHub (Jun 11, 2023): Can you download the beta API build [here](https://github.com/actualbudget/actual/suites/13524631684/artifacts/743556523)? (from [this build](https://github.com/actualbudget/actual/actions/runs/5238004769)). Once you’ve downloaded that zip, uncompress it to get a tgz file. Then pass that to `npm install /path/to/actual-api.tgz` to install it into your project. Can you try again and let me know what error you get (please send the full error log)?
Author
Owner

@bryce-hoehn commented on GitHub (Jun 12, 2023):

Running the beta api gave me a much clearer error message:

/home/user/node_modules/@actual-app/api/dist/app/bundle.api.js:30882
                        throw new Error('Could not get remote files');
                              ^

Error: Could not get remote files
    at handlers.api/download-budget (/home/bryce/node_modules/@actual-app/api/dist/app/bundle.api.js:30882:31)

Node.js v20.3.0

After seeing this error message I realized I had a typo in the password field.

I corrected the password then got another error saying:

await transaction = api.importTransactions("account-id", [
  ^^^^^^^^^^^^^^^^^

SyntaxError: Invalid left-hand side in assignment

but this was fixed by replacing "await" with "let" in that line.

It seems like it is now working! Thank you for your help.

<!-- gh-comment-id:1586425854 --> @bryce-hoehn commented on GitHub (Jun 12, 2023): Running the beta api gave me a much clearer error message: ``` /home/user/node_modules/@actual-app/api/dist/app/bundle.api.js:30882 throw new Error('Could not get remote files'); ^ Error: Could not get remote files at handlers.api/download-budget (/home/bryce/node_modules/@actual-app/api/dist/app/bundle.api.js:30882:31) Node.js v20.3.0 ``` After seeing this error message I realized I had a typo in the password field. I corrected the password then got another error saying: ``` await transaction = api.importTransactions("account-id", [ ^^^^^^^^^^^^^^^^^ SyntaxError: Invalid left-hand side in assignment ``` but this was fixed by replacing "await" with "let" in that line. It seems like it is now working! Thank you for your help.
Author
Owner

@davidhsv commented on GitHub (Oct 23, 2023):

I had the same problem. I had to run await api.downloadBudget('SYNC ID'); before the calling the import transactions. The clock is only initialised after this. Not sure how to avoid the need of the downloadBudget.

<!-- gh-comment-id:1776143185 --> @davidhsv commented on GitHub (Oct 23, 2023): I had the same problem. I had to run await api.downloadBudget('SYNC ID'); before the calling the import transactions. The clock is only initialised after this. Not sure how to avoid the need of the downloadBudget.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#7371