From 8ee6ed3ba163aa5e29ed2acb7b0030d613fa8645 Mon Sep 17 00:00:00 2001 From: Graham Blair Date: Tue, 5 Dec 2023 23:12:25 -0800 Subject: [PATCH] Implement delete_transaction API call --- monarchmoney/monarchmoney.py | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/monarchmoney/monarchmoney.py b/monarchmoney/monarchmoney.py index 317f7b3..a143873 100644 --- a/monarchmoney/monarchmoney.py +++ b/monarchmoney/monarchmoney.py @@ -624,6 +624,55 @@ async def create_transaction( variables=variables, ) + async def delete_transaction(self, transaction_id: str) -> bool: + """ + Deletes the given transaction. + + :param transaction_id: the ID of the transaction targeted for deletion. + """ + query = gql( + """ + mutation Common_DeleteTransactionMutation($input: DeleteTransactionMutationInput!) { + deleteTransaction(input: $input) { + deleted + errors { + ...PayloadErrorFields + __typename + } + __typename + } + } + + fragment PayloadErrorFields on PayloadError { + fieldErrors { + field + messages + __typename + } + message + code + __typename + } + """ + ) + + variables = { + "input": { + "transactionId": transaction_id, + }, + } + + response = await self.gql_call( + operation="Common_DeleteTransactionMutation", + graphql_query=query, + variables=variables, + ) + + if not response["deleteTransaction"]["deleted"]: + raise RequestFailedException(response["deleteTransaction"]["errors"]) + + return True + async def get_transaction_categories(self) -> Dict[str, Any]: """ Gets all the categories configured in the account.