Forum Academy Marketplace Showcase Pricing Features

API Connector: Dynamic List Size

I need to integrate Square instead of Stripe, which I am hoping to do so via API Connector. But either way, I don’t understand how to send an itemized list of products that the customer wishes to purchase.

I was able to initialize the follow:

But I need to be able to have a dynamic list of line items so that the request looks like this (this example as a list of 3 line items but this needs to be dynamic):

I have not been able to find a post that address this, or I am not understanding the posts I have looked at, so any help would be greatly appreciated.

Thank you.

Take your list of order items, and use the :format as text operator on it, to format each item into the correct JSON

Hmm… That’s new. :slightly_smiling_face: I had a different understanding of what format as text does.

Thanks for providing me a lead for me to doing some reason on this. I think I was able to find a posting/thread that talks about this: How to pass the list into API Connector? - #23 by axel.duheme However, I am not familiar with the syntax used in the body with the ampersands (&). It doesn’t look like JSON to me. Is this more a Bubble syntax? That said, it looks pretty intuitive what it is supposed to do. I just want to what language that is.

That’s new. :slightly_smiling_face: I had a different understanding of what format as text does.

Format as text is useful for a lot of things, but i think this is one of that main reasons they introduced it (certainly it was one of the examples they used to explain its use when it was first released, if I recall correctly).

However, I am not familiar with the syntax used in the body with the ampersands (&). It doesn’t look like JSON to me. Is this more a Bubble syntax?

Yeah, that’s not JSON in the link you shared there… that’s just URL query parameters (which is how Stripe take their API request).

If the API you’re using requires JSON request then you’ll have to use JSON in your request body.

@adamhholmes @doug.burden

I was able to modify the above API call to this:

with the value of LineItem being:
[{"quantity": "1", "base_price_money": {"amount": 100, "currency": "USD"}, "name": "ProductName"}]

But when I edit my workflow, the request is giving me errors:

I tried to fix the errors, but the 3rd error message doesn’t make sense to me because I think that would break the JSON syntax.

Error 1: "invalid character '[' looking for beginning of object key string (line 4, character 123)"
Error 2: "invalid character '{' looking for beginning of object key string (line 4, character 121)"
Error 3: "invalid character ':' after object key:value pair (line 4, character 31)"

UPDATE: I have removed all the spaces from the syntax. Error still shows. If I add format as JSON-safe, a new error pops up "Expected an array."

Yeah, you’re including the array brackets in every item - which is incorrect. They should be at the start and end of the array only - with everything else inside them.

The simplest way will just be to add the square brackets to the JSON in the API connector, and keep everything inside them dynamic.

Or you can add them in the LineItems dynamic value in your API Action box

e.g.

[Search for Carts: first item’s: Cart Items: format as text]

Thank you. The first solution worked.

I tried the 2nd solution, but another similar error occurred. I also thought it was an index issue, so I tried a [count - 1], but that didn’t work either.

Now it does.

1 Like