monarch-money-api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Philip G Bassham
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,156 @@
1
+ ## Unofficial Monarch Money API
2
+ This is an unofficial Javascript API for Monarch Money. It is not endorsed by Monarch Money and may break at any time. Use at your own risk.
3
+
4
+ ## Getting Started
5
+ You can deploy this on Vercel or Repl.it. You can also run it locally.
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm i monarch-money-api
10
+ ```
11
+
12
+ ## Configuration
13
+ You will need to create a user token, that you will save as an environment variable in order to use the API.
14
+
15
+ #### Create a token using the CLI:
16
+
17
+ #### 1. Create a file named `login.js` and add the following code:
18
+
19
+
20
+ ```javascript
21
+ import { interactiveLogin } from "monarch-money-api";
22
+
23
+ interactiveLogin();
24
+ ```
25
+
26
+ Save.
27
+
28
+ #### 2. Run the script and enter your credentials:
29
+ Enter this in your teminal and press enter:
30
+ ```bash
31
+ node login.js
32
+ ```
33
+ You will be prompted to enter your email, password, and 2FA code if you have 2FA enabled.
34
+
35
+ #### 3. Save the token in your `.env` file:
36
+ After you have logged in, you will be given a token. Copy this token and add it to your `.env` file. (Create a `.env` file if you don't have one.)
37
+
38
+ ```env
39
+ MONARCH_TOKEN=your_token_here
40
+ ```
41
+
42
+ > [!TIP]
43
+ > If deploying to Vercel, you can add an environment variable in local and production environments with the vercel cli:
44
+ > ```bash
45
+ > vercel env add token
46
+ > ```
47
+
48
+ ## Usage Example
49
+ ```javascript
50
+ import { getAccounts, getBudgets } from "monarch-money-api";
51
+
52
+ const accounts = await getAccounts();
53
+ console.log("Accounts:", accounts);
54
+
55
+ const budgets = await getBudgets();
56
+ console.log("Budgets:", budgets)
57
+ ```
58
+
59
+
60
+ ## Vercel Example
61
+ You can deploy this to Vercel by creating a new project and adding the token as an environment variable. You can then use the API in your serverless functions.
62
+
63
+ If you want to use the API in a serverless function, you can create a new file in the `api/budget.js` directory and add the following code:
64
+
65
+ ```javascript
66
+ import { getBudgets } from "monarch-money-api";
67
+
68
+ export default async function handler(req, res) {
69
+ try {
70
+ const budgets = await getBudgets();
71
+ console.log("Budgets:", budgets)
72
+
73
+ res.status(200).json(budgets);
74
+ } catch (error) {
75
+ res.status(500).json({ error: error.message });
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## API Methods
81
+
82
+ ```js
83
+ interactiveLogin(useSavedSession = true, saveSession = true)
84
+
85
+ login(email, password, useSavedSession = true, saveSession = true, mfaSecretKey = null)
86
+
87
+ multiFactorAuthenticate(email, password, code)
88
+
89
+ getAccounts()
90
+
91
+ getAccountTypeOptions()
92
+
93
+ getRecentAccountBalances(startDate = null)
94
+
95
+ getAccountSnapshotsByType(startDate, timeframe)
96
+
97
+ getAggregateSnapshots(startDate = null, endDate = null, accountType = null)
98
+
99
+ createManualAccount(accountType, accountSubType, isInNetWorth, accountName, accountBalance = 0)
100
+
101
+ updateAccount(accountId, accountName = null, accountBalance = null, accountType = null,accountSubType = null, includeInNetWorth = null, hideFromSummaryList = null, hideTransactionsFromReports = null)
102
+
103
+ deleteAccount(accountId)
104
+
105
+ requestAccountsRefresh(accountIds)
106
+
107
+ isAccountsRefreshComplete(accountIds = null)
108
+
109
+ requestAccountsRefreshAndWait(accountIds = null, timeout = 300, delay = 10)
110
+
111
+ getAccountHoldings(accountId)
112
+
113
+ getAccountHistory(accountId)
114
+
115
+ getInstitutions()
116
+
117
+ getBudgets(startDate = null, endDate = null, useLegacyGoals = false, useV2Goals = true)
118
+
119
+ getSubscriptionDetails()
120
+
121
+ getTransactionsSummary()
122
+
123
+ getTransactions({ limit = 100, offset = 0, startDate = null, endDate = null, search = "",categoryIds = [], accountIds = [], tagIds = [], hasAttachments = null, hasNotes = null, hiddenFromReports = null, isSplit = null, isRecurring = null, importedFromMint = null, syncedFromInstitution = null })
124
+
125
+ createTransaction({ date, accountId, amount, merchantName, categoryId, notes = "", updateBalance = false })
126
+
127
+ deleteTransaction(transactionId)
128
+
129
+ getTransactionCategories()
130
+
131
+ deleteTransactionCategory(categoryId)
132
+
133
+ deleteTransactionCategories(categoryIds)
134
+
135
+ getTransactionCategoryGroups()
136
+
137
+ createTransactionCategory({ groupId, transactionCategoryName, rolloverStartMonth = new Dat(), icon = "\u2753", rolloverEnabled = false, rolloverType = "monthly" })
138
+
139
+ createTransactionTag(name, color)
140
+
141
+ getTransactionTags()
142
+
143
+ setTransactionTags(transactionId, tagIds)
144
+
145
+ getTransactionDetails(transactionId, redirectPosted = true)
146
+
147
+ getTransactionSplits(transactionId)
148
+
149
+ updateTransactionSplits(transactionId, splitData)
150
+ ```
151
+
152
+ ## Credits
153
+
154
+ This API is based on a lot of [Monarch Money](https://github.com/hammem/monarchmoney) to reverse engineer the Monarch Money API.
155
+
156
+ ## License
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ schema: "https://api.monarchmoney.com/graphql",
3
+ // documents: './src/**/*.graphql',
4
+ extensions: {
5
+ endpoints: {
6
+ default: {
7
+ url: "https://api.monarchmoney.com/graphql",
8
+ headers: {
9
+ Authorization: `Token ${process.env.token}`,
10
+ },
11
+ },
12
+ },
13
+ },
14
+ }