Skip to content

Commit

Permalink
Merge pull request #62 from hammem/add_categories
Browse files Browse the repository at this point in the history
  • Loading branch information
grablair authored Jan 5, 2024
2 parents ce6455d + c8cad27 commit 658d32a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ As of writing this README, the following methods are supported:

## Mutating Methods

- `delete_transaction_category` - deletes a category for transactions
- `request_accounts_refresh` - requests a syncronization / refresh of all accounts linked to Monarch Money. This is a **non-blocking call**. If the user wants to check on the status afterwards, they must call `is_accounts_refresh_complete`.
- `request_accounts_refresh_and_waid` - requests a syncronization / refresh of all accounts linked to Monarch Money. This is a **blocking call** and will not return until the refresh is complete or no longer running.
- `request_accounts_refresh_and_wait` - requests a syncronization / refresh of all accounts linked to Monarch Money. This is a **blocking call** and will not return until the refresh is complete or no longer running.
- `create_transaction` - creates a transaction with the given attributes
- `update_transaction` - modifes one or more attributes for an existing transaction
- `update_transaction_splits` - modifes how a transaction is split (or not)
Expand Down
51 changes: 51 additions & 0 deletions monarchmoney/monarchmoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,57 @@ async def get_transaction_categories(self) -> Dict[str, Any]:
)
return await self.gql_call(operation="GetCategories", graphql_query=query)

async def delete_transaction_category(self, category_id: str) -> bool:
query = gql(
"""
mutation Web_DeleteCategory($id: UUID!, $moveToCategoryId: UUID) {
deleteCategory(id: $id, moveToCategoryId: $moveToCategoryId) {
errors {
...PayloadErrorFields
__typename
}
deleted
__typename
}
}
fragment PayloadErrorFields on PayloadError {
fieldErrors {
field
messages
__typename
}
message
code
__typename
}
"""
)

variables = {
"id": category_id,
}

response = await self.gql_call(
operation="Web_DeleteCategory", graphql_query=query, variables=variables
)

if not response["deleteCategory"]["deleted"]:
raise RequestFailedException(response["deleteCategory"]["errors"])

return True

async def delete_transaction_categories(
self, category_ids: List[str]
) -> List[bool]:
"""
Deletes a list of transaction categories.
"""
return await asyncio.gather(
*[self.delete_transaction_category(id) for id in category_ids],
return_exceptions=True,
)

async def get_transaction_category_groups(self) -> Dict[str, Any]:
"""
Gets all the category groups configured in the account.
Expand Down

0 comments on commit 658d32a

Please sign in to comment.