Use an IIAFE in the API example code

This commit is contained in:
Jed Fox
2023-04-06 19:45:27 -04:00
committed by GitHub
parent f20bed8e9f
commit 8fa23838c0

View File

@@ -31,25 +31,27 @@ Next, youll need connect to your running server version of Actual to access y
```js
let api = require('@actual-app/api');
await api.init({
// Budget data will be cached locally here, in subdirectories for each file.
dataDir: '/some/path',
// This is the URL of your running server
serverURL: 'http://localhost:5006',
// This is the password you use to log into the server
password: 'hunter2',
});
(async () => {
await api.init({
// Budget data will be cached locally here, in subdirectories for each file.
dataDir: '/some/path',
// This is the URL of your running server
serverURL: 'http://localhost:5006',
// This is the password you use to log into the server
password: 'hunter2',
});
// This is the ID from Settings → Show advanced settings → Sync ID
await api.downloadBudget('1cfdbb80-6274-49bf-b0c2-737235a4c81f');
// or, if you have end-to-end encryption enabled:
await api.downloadBudget('1cfdbb80-6274-49bf-b0c2-737235a4c81f', {
password: 'password1',
});
// This is the ID from Settings → Show advanced settings → Sync ID
await api.downloadBudget('1cfdbb80-6274-49bf-b0c2-737235a4c81f');
// or, if you have end-to-end encryption enabled:
await api.downloadBudget('1cfdbb80-6274-49bf-b0c2-737235a4c81f', {
password: 'password1',
});
let budget = await api.getBudgetMonth('2019-10');
console.log(budget);
await api.shutdown();
let budget = await api.getBudgetMonth('2019-10');
console.log(budget);
await api.shutdown();
})();
```
Heads up! You probably dont want to hard-code the passwords like that, especially if youll be using Git to track your code. You can use environment variables to store the passwords instead, or read them in from a file, or request them interactively when running the script instead.