Created
May 25, 2020 19:57
-
-
Save katoen/16b81b6f06972206cc29a6754056dd36 to your computer and use it in GitHub Desktop.
YNAB API Power BI - POST Transactions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* POST YNAB.com new transactions in Power BI Power Query | |
https://api.youneedabudget.com/v1#/Transactions/createTransaction | |
Store all rows to be POSTED in seperate Query #"YNAB-POSTPREP" | |
Use one api call for each transaction | |
Log responses from YNAB all KEYS & IDs stored as parameters | |
*/ | |
let | |
Source = #"YNAB-POSTPREP", | |
YNABPOST = Table.AddColumn( | |
Source, | |
"YNAB", | |
each Json.Document( | |
Web.Contents( | |
"https://api.youneedabudget.com/v1/budgets/" & YNABBudgetID & "/transactions", | |
[Headers = [ | |
#"Content-Type" = "application/json", | |
accept = "application/json", | |
Authorization = "Bearer " & YNABAPIKEYPOST | |
], | |
// POST transaction content | |
Content = Json.FromValue( | |
[transaction = [ | |
account_id = [YNABAccounts.id], | |
date = [DATE], | |
amount = [AMOUNT], | |
payee_name = [PAYEE], | |
memo = [MEMO], | |
import_id = [TRANSACTIONID] | |
]] | |
)] | |
) | |
) | |
), | |
#"Expanded YNAB" = Table.ExpandRecordColumn(YNABPOST, "YNAB", {"data"}, {"data"}), | |
#"Expanded data" = Table.ExpandRecordColumn( | |
#"Expanded YNAB", | |
"data", | |
{"transaction_ids"}, | |
{"transaction_ids"} | |
), | |
#"Extracted Values" = Table.TransformColumns( | |
#"Expanded data", | |
{"transaction_ids", each Text.Combine(List.Transform(_, Text.From), ";"), type text} | |
), | |
#"Changed Type" = Table.TransformColumnTypes(#"Extracted Values", {{"AMOUNT", Int64.Type}}) | |
in | |
#"Changed Type" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment