Skip to content

Instantly share code, notes, and snippets.

@katoen
Created May 25, 2020 19:57
Show Gist options
  • Save katoen/16b81b6f06972206cc29a6754056dd36 to your computer and use it in GitHub Desktop.
Save katoen/16b81b6f06972206cc29a6754056dd36 to your computer and use it in GitHub Desktop.
YNAB API Power BI - POST Transactions
/* 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