Sending Data to API from Repearing Group

Hey there

I’m trying to create an invoice in Xero. When I send a single line item, it works fine. The moment I add another line item to the invoice, I get an error.

My API JSON Body is as follows:

{
“Invoices”: [
{
“Type”: “ACCREC”,
“Contact”: {
“ContactNumber”: “”
},
“LineItems”: [
{
“Description”: “”,
“Quantity”: “”,
“UnitAmount”: “”
}
],
“Date”: “”,
“Reference”: “”,
“DueDate”: “”,
}
]
}

I am trying to send the following for the line item section (with an unlimited amount of lines):

“LineItems”: [
{
“Description”: “”,
“Quantity”: “”,
“UnitAmount”: “”
},
{
“Description”: “”,
“Quantity”: “”,
“UnitAmount”: “”
}
]

But, when I choose to send the data, it is sending as:

“LineItems”: [
{
“Description”: “Tools2, asdasd”,
“Quantity”: “11, 1”,
“UnitAmount”: “123, 123”
},
],

How do I force Bubble.io to not add a comma “,” between the line items and create a whole new line item as per the code I’m trying to achieve?

“LineItems”: [
{
“Description”: “”,
“Quantity”: “”,
“UnitAmount”: “”
},
{
“Description”: “”,
“Quantity”: “”,
“UnitAmount”: “”
}
]

TIA

You need to use :format as text to send the rg items in the correct json format.

1 Like

I actually have a text field on my invoice line items data type for the JSON to send to Xero.

Screen Shot 2021-10-24 at 7.41.51 am

And then I send it through API like this (I have a field on my invoice data type that is a list of invoice lines)
Screen Shot 2021-10-24 at 7.43.42 am

Would :find and replace work here?

Thanks so much, this looks like the best method, but I’m getting an error:

This is what I’m sending:

But getting this response:

Any ideas?

I think it’s giving you some great specifics on where to look within the error message :wink:

I always run my JSON through this validator https://jsonlint.com/ to double check I have the structure right :slight_smile:

2 Likes

Hey again - i’ve spent a long time trying to work this out. Still no luck. I am not sure where I’m going wrong.

I’ve updated the JSON using the super handy tool you provided:

All’s working OK…

But still get an error:

did you define the apibody in raw text or using the form inputs

Used a workflow to turn the list into text formatted as per the image with [{ }]

What’s your set up in the API connector?

the issue is a malformed json. not really your doing but still your issue to deal with. in your example, you are using fancy quotation marks thanks to bubbles inference engine and assuming you want to use human friendly text and not machine friendly text

instead of pressing the quotation mark button on your keyboard when entering that dynamic expression into bubble, please try copy/pasting the following character for all quotation marks you include in your expression

"

Just tried this, and now returning a slightly different error;

Remove the spaces in your parameters (not sure it helps) but I meant to use them where you input the data to the api call. Not in the api editor. Sorry for the confusion.

Tried that, no luck:

image

image

If anyone can give a solution, I will give a reward :wink:

:moneybag: :joy:

In your api body call, can you remove the paréntesis around the line items array input. It should be like this

"LineItems”: [<LineItems>]

Essentially what you’ve done is told the API connector to send a string who’s first and last characters are the square brackets

Make your Json body in the same way

1 Like

a @jared.gibb said, don’t have your " " around your line items as " " denotes a string (so a single value or a list of values that go under that item heading) so it was getting confused thinking it was getting a string but you were sending an array (a repeating list of an item set)

The JSON was technically correct, so that’s why it got validated in JSON lint, its just that the structure of the values you were putting in wasn’t matching the structure of the JSON body template you had set up.
…if that makes sense? :slight_smile:

So in your API connector body have as Jared said above or

“LineItems”: <line_items>

and put the square bracket in your api workflow around your list of line items JSON dynamic data.

1 Like

Thank you so much @equibodyapp and @jared.gibb.

Got it working this morning! :slight_smile:

2 Likes