Posh-YNAB icon indicating copy to clipboard operation
Posh-YNAB copied to clipboard

Api endpoints

Open hershsa opened this issue 7 years ago • 2 comments

Added switches to Get-YnabCategory, month and CategoryID to allow cmdlet to retrieve data from this API endpoint - /budgets/{budget_id}/months/{month}/categories/{category_id}

Also added to Jsonparse to include goal data in the single category portion.

hershsa avatar Jan 03 '19 23:01 hershsa

Alright I had a chance to look at this and have a couple of questions/issues, and would be interested in your input.

Month

You are defining $Month as an array of strings ([String[]]) but you are not iterating over it in the process block. I'm not sure how we would return the data to the user. We could add a 'Month' column to the data, but if they also request multiple categories it can get complicated. I believe we should split the data further into a Months section.

Month      Categories
-----      ----------
2018-12-01 {@{Category=Bank Rewards; Note=; Budgeted=0;...}}
2019-01-01 {@{Category=Bank Rewards; Note=; Budgeted=0;...}}

Alternatively we could add a Month header to the data:

Month    : 2016-12-01
Category : Natural Gas
Budged   :
Activity : -80.84
Balance  : 0

Month    : 2017-01-01
Category : Natural Gas
Budged   :
Activity : -52.14
Balance  : 0

Also your Month flag does not support returning data for multiple categories. Do you think there is value in being able to say, "Show me data for December and January for my Food, Fuel, and Leisure categories"? I'm not sure if it's worth the effort to add the functionality vs just implementing the API to spec.

CategoryID

When I first started building this module I included the ability to specify IDs as well as Names as identifiers for items like Budgets, Accounts, Categories, etc. This quickly became unmanageable with hundreds of branching parameter sets, trying to ensure that either an ID or Name is specified for every call. I eventually settled on making the Name a required field and dropping the IDs completely, instead performing lookups for IDs based on names. I understand this removes a bit of flexibility and also slows things down if you already have the ID on hand.

An alternative may be to use the Category parameter for both values, simply treating the value as an ID if it matches a certain regex pattern (^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$). I will have to implement this in every function call, but it might be worth it for speed and useability.

In the meantime I propose removing your CategoryID change and instead suggest we use the Category.

ConnorGriffin avatar Jan 08 '19 23:01 ConnorGriffin

I rewrote this to meet my own requirements on a branch called 'feat/CategoryMonth'. Let me know what you think.

> Get-YnabCategory -Category 'Work Food','Drinking','Electricity' -Month 2018-11-04,2018-12-01,(get-date) | select * -exclude CategoryID | ft -autosize

Month      Category    Note Budgeted Activity Balance Hidden
-----      --------    ---- -------- -------- ------- ------
2018-11-01 Work Food          152.12  -152.12       0  False
2018-12-01 Work Food            71.5    -71.5       0  False
2019-01-01 Work Food             125   -45.69   79.31  False
2018-11-01 Drinking               20        0      20  False
2018-12-01 Drinking               20        0      40  False
2019-01-01 Drinking               20   -94.63  -34.63  False
2018-11-01 Electricity           149     -149       0  False
2018-12-01 Electricity           149     -149       0  False
2019-01-01 Electricity          74.5        0    74.5  False

ConnorGriffin avatar Jan 09 '19 00:01 ConnorGriffin