Skip to content

Commit

Permalink
Add create_transaction method
Browse files Browse the repository at this point in the history
  • Loading branch information
grablair committed Nov 8, 2023
1 parent 7d4cece commit faf6623
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions monarchmoney/monarchmoney.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,59 @@ async def get_transactions(
operation="GetTransactionsList", graphql_query=query, variables=variables
)

async def create_transaction(
self,
date: str,
account_id: str,
amount: float,
merchant_name: str,
category_id: str,
notes: str = ""
) -> Dict[str, Any]:
"""
Creates a transaction with the given parameters
"""
query = gql(
"""
mutation Common_CreateTransactionMutation($input: CreateTransactionMutationInput!) {
createTransaction(input: $input) {
errors {
...PayloadErrorFields
__typename
}
__typename
}
}
fragment PayloadErrorFields on PayloadError {
fieldErrors {
field
messages
__typename
}
message
code
__typename
}
"""
)

variables = {
"input": {
"date": date,
"accountId": account_id,
"amount": round(amount, 2),
"merchantName": merchant_name,
"categoryId": category_id,
"notes": notes
}
}

return await self.gql_call(
operation="Common_CreateTransactionMutation", graphql_query=query, variables=variables
)


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

0 comments on commit faf6623

Please sign in to comment.