jhonderson / actual-http-api

Basic Actual Budget API exposed through HTTP endpoints
MIT License
40 stars 9 forks source link

Is Account Ordering Possible? #16

Closed culpeppers closed 2 months ago

culpeppers commented 2 months ago

Looking through Actual's API it looks like you are returning every property of an Account they expose, but I just wanted to ask if you knew of a way to pull any additional information or properties to determine the order the accounts should be listed in, specifically the same order they are in on the web. Thanks!

jhonderson commented 2 months ago

Hey there, the api already returns the accounts sorted as they appear in the ui, see the nodejs api logic: https://github.com/actualbudget/actual/blob/master/packages/loot-core/src/server/db/index.ts#L570

Unfortunately the nodejs api doesn’t return anymore fields that can be used for sorting, only these 4 fields: https://github.com/actualbudget/actual/blob/master/packages/loot-core/src/server/api-models.ts#L18-L25

If you want to sort based on a field that is not there, or based in the order from the UI but say in reverse, you would have to modify the nodejs actual api (pull request) to expose the fields you want to use.

We could also change this http api to use the ActualQL language to query the accounts and sort them somehow, but seems more like a hack, so I like the former approach more.

culpeppers commented 2 months ago

That makes sense thank you! The issue must be in how I'm processing and storing the accounts.

I have another question related to categories and budget months. Should I ask here or open another issue?

jhonderson commented 2 months ago

You can ask here too

culpeppers commented 2 months ago

Great thanks!

I am trying to better understand the relationship, if any, between BudgetMonthCategoryGroup / BudgetMonthCategory and CategoryGroup/Category. I know they have the same ids, though don't share every single property. How each impacts the overall budget is still confusing me a bit.

For example, if I want to rename a category, do I update both objects, or just one? Same with deleting a category. I created a test category and then went to delete it. Since there is only a delete for a Category, that worked fine. However, with no method to delete a BudgetMonthCategory, that remained and it appears deleting just the Category had no impact at all. Does that mean CategoryGroup and Category don't need to be used at all?

I know that was long, but I appreciate any help!

jhonderson commented 2 months ago

BudgetMonthCategory represents the category properties that are tied to a specific month, I.e budgeted amount, and carry over. Category represents the category configuration, name, grouping, hidden, etc. To manage categories use the Category endpoints, to change budgeted amounts for a particular month and category, use BudgetMonthCategory.

If you want to delete a category, the Category delete endpoint should do it. If it didn’t work it’s probably cuz you have transactions using that category, so you want to update those transactions to point to a different category, and then delete the category. You can achieve this by using the query parameter transfer_caregory_id offered by the delete category endpoint.

culpeppers commented 2 months ago

That is incredibly helpful, thank you so much!

culpeppers commented 2 months ago

Going back to my accounts ordering question. I ran some test queries in Postman on accounts, and it does return in the same order each time, but it is not in the order that the UI has. I cannot tell why it is returning in the specific order it is, to be honest heh.

jhonderson commented 2 months ago

Mmmm strange. You can try exporting your data from the Ui, that gives you a zip file. You unzipped and you get a db.sqlite file. You can open it with any SQLite viewer, and explore the records in the table accounts. There there is a column called sorting or something like that. That tells you what is the sorting of your accounts. AFAIK that’s the sorting used in the Ui, and that’s the order used by the api too. It appears in that order for me.

Can you try the request using curl command ? Maybe Postman is formatting the output ?

culpeppers commented 2 months ago

I tried it using curl and its the same order as Postman and how I implemented it. I will look at the sqlite file and see what is going on. I figured it was something wonky with my budget haha.

I appreciate your help!

jhonderson commented 2 months ago

You are very welcome!