bvanelli / actualpy

Python API implementation for Actual server - reference https://actualbudget.org/
16 stars 4 forks source link

Update transactions via api calls #40

Closed esseti closed 1 month ago

esseti commented 1 month ago

Description

Is it possible to do something of this via the api?

https://github.com/actualbudget/actual/issues/3034#event-13468944383

i can download the list of transaction and i know how to parse the payee and the notes, but then:

bvanelli commented 1 month ago

Hello, I don't if I fully understand what you want to do, but you basically want to change transactions based on a local regex? What makes this library unique is that you can change the objects freely and then commit the results just like you would on a normal database:

from actual import Actual
from actual.queries import get_transactions

changed_payees = set()
with Actual(password="mypass", file="CSV Import") as actual:
    for transaction in get_transactions(actual.session):
        # change the transactions notes
        if transaction.notes is not None:
            transaction.notes = transaction.notes + " my suffix!"
        # change the payee name
        if transaction.payee and transaction.payee.name is not None:
            # check if this payee wasn't changed before yet
            if transaction.payee_id not in changed_payees:
                transaction.payee.name = transaction.payee.name + " my suffix!"
                changed_payees.add(transaction.payee_id)
    # commit your changes!
    actual.commit()

I used the example CSV Import from the examples folder as a reference. Here is the before transactions:

image

And here is the after results:

image

Is this what you meant?

esseti commented 1 month ago

Oh, that's great! i thought i've to do some api calls or somethings.

bvanelli commented 1 month ago

I'll leave this issue open until I write some documentation on how to modify existing transactions.