json add array
Hi everyone, i have spend several hours solving this Problem. I have this code:
let myURL := "";
let myBearer := (select Einstellungen).'Bexio API-Token';
let contact_id := Kontakt.'Bexio ID';
let user_id := 'Projektleiter 1'.'Bexio User ID';
let invoice_positions := for i in Projektpositionen do
{
amount: i.Anzahl,
unit_price: i.Verkaufspreis,
text: i.Artikelname,
type: "KbPositionCustom",
tax_id: number((select Einstellungen).'Bexio Tax ID'),
discount_in_percent: i.'Positionsrabatt Prozent'
}
end;
let zwischentotal := {
text: "Zwischentotal",
type: "KbPositionSubtotal"
};
let myHeaders := {
'content-type': "application/json",
Accept: "application/json",
Authorization: "Bearer " + myBearer
};
let myBody := {
title: Rechnungstitel,
contact_id: contact_id,
pr_project_id: 'Projektleiter 1'.'Bexio ID',
bank_account_id: (select Einstellungen).'Bexio Bankkonto ID',
mwst_is_net: true,
is_valid_from: format(today(), "YYYY-MM-DD"),
user_id: user_id,
positions: invoice_positions
};
let oauth := do as server
http("POST", myURL, myHeaders, formatJSON(Text))
end;
this is working just fine i get some products as i want. now i want to add this code to the myBody positions:invoice_positions.. i guess its like append to the array which i get from my loop.
any suggestions?
2 replies
-
You could try:
let myURL := ""; let myBearer := (select Einstellungen).'Bexio API-Token'; let contact_id := Kontakt.'Bexio ID'; let user_id := 'Projektleiter 1'.'Bexio User ID'; let zwischentotal := { text: "Zwischentotal", type: "KbPositionSubtotal" }; let myHeaders := { 'content-type': "application/json", Accept: "application/json", Authorization: "Bearer " + myBearer }; let myBody := { title: Rechnungstitel, contact_id: contact_id, pr_project_id: 'Projektleiter 1'.'Bexio ID', bank_account_id: (select Einstellungen).'Bexio Bankkonto ID', mwst_is_net: true, is_valid_from: format(today(), "YYYY-MM-DD"), user_id: user_id, positions: for i in Projektpositionen do { amount: i.Anzahl, unit_price: i.Verkaufspreis, text: i.Artikelname, type: "KbPositionCustom", tax_id: number((select Einstellungen).'Bexio Tax ID'), discount_in_percent: i.'Positionsrabatt Prozent' } end; }; let oauth := do as server http("POST", myURL, myHeaders, formatJSON(Text)) end;
Just wondering why let myBearer := (select Einstellungen).'Bexio API-Token'; does work though....
I would think using like this (using the first() function) :
let myBearer := first((select Einstellungen).'Bexio API-Token');
Also for the bank account and the tax ID.
-
Thank you for your time Steven.
as Einstellungen (settings) is a page and not table I assumed that first() is not necessary as there are no other entries..
as for my other problem to add some values to my array I gave up after 8 hours trying .
my new approach now is to add the values to my subtable Projektpositionen so no need to append the array..
Appreciate your time Steven as I’m new to Ninox :)
Content aside
- Status Answered
- 8 mths agoLast active
- 2Replies
- 117Views
-
2
Following