Sending multiple data arrays in one API call

Hi bubblers

im trying to make an API where i can send invoices to another application.. and im struggling with how bubble understand when i want to send multiple arrays/invoice lines in the invoice

{
  "currency": <currency>,
  "language": <language>,
  "description": <description>,
  "comment": <comment>,
  "date": <date>,
  "productLines": [
    {
      "description": <description_lines>,
      "quantity": <quantity>,
      "accountNumber": <accountNumber>,
      "unit": <unit>,
      "discount": <discount>,
      "lineType": <lineType>,
      "baseAmountValue": <baseAmountValue>
    }
  ],
  "address": <address>,
  "showLinesInclVat": <showLinesInclVat>,
  "contactGuid": <contactGuid>,
  "paymentConditionNumberOfDays": <paymentConditionNumberOfDays>,
  "paymentConditionType": <paymentConditionType>,
}

this is the JSON that i try to send to the API.. and the line “productlines” should be dynamic data..

but i cant figure how to set the logic in bubble for how many lines a invoice have since that is different from invoice to invoice..

Let’s say you have a DB productline

{
  "currency": <currency>,
  "language": <language>,
  "description": <description>,
  "comment": <comment>,
  "date": <date>,
  "productLines": [<productlines>],
  "address": <address>,
  "showLinesInclVat": <showLinesInclVat>,
  "contactGuid": <contactGuid>,
  "paymentConditionNumberOfDays": <paymentConditionNumberOfDays>,
  "paymentConditionType": <paymentConditionType>,
}

In api connector
For the productline parameters in action, you should use
Do a search for productline:format as text
in the format as text, you will set, on the top box:

    {
      "description": "This item description(dynamic)",
      "quantity": This item quantity(dynamic),
      "accountNumber": This item accountnumber(dynamic),
      "unit": This item unit(dynamic),
      "discount": This item discount(dynamic),
      "lineType": This item linetype(dynamic),
      "baseAmountValue": This item basemountvalue(dynamic)
    }

(I didn’t add doubles quotes everywhere… so check API documentation to add them where it’s needed)
on the bottom box, just put a comma (as delimiter)

hej @Jici

thank you for you help :slight_smile:
they way you decribe it sound easy.. :sweat_smile:

and i tried something myself before you wrote and see i get close..
image

as you see i use the expression each item's name and each items amount

should i just delete all the value of product line and make a do a search for productline in there?

Please… read again… I show you using a do a search…in your case, it’s
Current page’s case’s invoice lines:format as text that goes in the (body) productlines field
You will set the JSON of productlinein the format as text function…

but what do i write in the parameters value field to initialize it?

In API connector, you seem to have set the correct value to initialize the call (The json object). (But if you already have it initialized, you don’t need to initialize it again)

oh okay..


so this is how it should look?

Yes and no
For sure, you will have an error in your JSON. "lineType" is a string accordin to your screenshot, so product need to be double quotes around it "linetype":"Product", Like I said, in my JSON, I didn’t set them because I don’t know what API expect. Check API Doc to be sure you are creating the JSON correctly.

For description, be careful if you expect special characters that could break the json.
You could instead do: "description":This innvoice list's name:formatted as JSON-safe,. As you can see, I didn’t set double quotes around This invoice list’s name:formatted as JSON-safe because this function will add them automatically but also escape special characters.

aaah.. that make sense.. learning something new today :smiley:

then i have another question also because in the documentation it says units only accepts: hours, parts, km, day, week, month, kilogram, cubicMetre, set, litre, box, case, carton, metre, package, shipment, squareMetre, session, tonne.

but in my application i use: “timer, stk, kvm, uger, måneder” and so on.. so danish definitions of them.. is there a way to make the API understand that?

here is a link to the doc btw: API Docs

Are you using option set for your units?

yeah i am

Create a new field in your option set and translate the display value into something API accept.
In your unit parameters use This units(option set)'s new field instead of 's display (use the name of the field you set :wink: )

hmm.. im not sure what you mean with that :thinking:

Go in option set for your units (seem to be called enheder)
Click on Create a new attribute. Let’s call it “Dinero API Unit”. Select “text” for the type
Click on modify attribute of each of your “enheder” Add the value for each of time in this new field using the accepted value by API. Let’s say “timer” will be “hours”

Now in your JSON, modify "This invoice list's enheder's display" For: "This invoice list's enheder's Dinero API Unit"

genious!!

but still there is something not right :thinking:

401 is unauthorized. Check your API auth a scopes (if there’s scopes…)

ooh yeah it expired after while

but okay its authorized again..
and now i get this message:
image

{"code":42,"message":"Validation Error","validationErrors":{"Body":"The body does not match expected schema"},"languageSpecificMessages":[{"property":"message","message":"Der er fejl i de data, du har angivet."},{"property":"Body","message":"The body does not match expected schema"}],"errorMessageList":[{"Code":"Body","Message":"The body does not match expected schema"}]}

can you share the whole settings in API connector?

hope its readable

showLinesInclVat should be false without double quotes. Same for paymentConditionNumberOfDays. However, this is possible that the API accept boolean and integer as string.
You can use tools like beeceptor or requestbin to send the request and inspect it.
This will be easier to find what can be the issue but also to validate the JSON