How to send list of lists via API connector

Hello, I’m trying to find a workaround to send a list of data to an external custom API (i.e. AWS Lambda function). Simplified scenario: for each User I have height and weight. Suppose I want to for some users get their BMI = weight/height^2 via my external function:

POST(JSON={[list of weights], [list of heights]}) → API → Response ([list of BMIs])

(I have a much more complex computation than this but it illustrates the issue). Visually, here is what I need:

What I’ve tried:

  • In a workflow I can retrieve the response by for example setting for some custom state =
    Get data from external API →
    listofweights= Search for users that fit criteria : formatted as text : text is each user’s weight : comma delimiter
    listofheights= Search for users that fit criteria : formatted as text : text is each user’s height : comma delimiter

image

This does not work, and I’m hunting for a workaround to sending a (variable length) list of data to an external API.

For context: there’s a bug in Bubble. If you do the above process on the page i.e. a dynamic text in a text box, it works absolutely as intended. If you do it in a workflow, then the first text calculated will overwrite all the rest (reproducible example). Flagged to Bubble, but I need to find a workaround urgently and I haven’t heard back from them yet.

Edit: I should have specified: there’s a simple method where you do Search by users → 's height → join with “,”.

I do that method when I just need to send a simple list, problem arises when I need to send lists of lists. For example if each User has a field “visited locations”, and I want to send:

[[Japan; France], [USA; UK; Japan], … ]

Etc. Then I have to do two nested layers (i.e. first is list of users: formatted as text (delimited “,”), then for each user get all visited locations, format this as text (delimited “;”)) . The simple method (search for all user’s visited locations → formatted as text (delimited “;”)) results in:

[Japan; France;USA; UK; Japan; … ]

1 Like

Can you share editor link?
I don’t really see issue in your example.
Also, when you need a CSV list of a field, you can just basically use Do a search for user’s height:join with ,
Can you also provide a link to API Doc?

Hi Jici -

  1. Editor link here. The problem is subtle, but basically notice that the outcome on the right hand side should be the same as the outcome of the left hand side. The only difference is the order in which the custom states are calculated flips. The custom state is attached to the first button. Anyway, I suppose I can’t help it so trying to find a workaround.

  2. Yes, I should have specified (I’ll update post): I do that method when I just need to send a simple list, problem arises when I need to send lists of lists. For example if each User has a field “visited locations”, and I want to send:

[[Japan; France], [USA; UK; Japan], … ]

Etc. Then I have to do two nested layers (i.e. first is list of users: formatted as text (delimited “,”), then for each user get all visited locations, format this as text (delimited “;”)) . The simple method (search for all user’s visited locations → formatted as text (delimited “;”)) results in:

[Japan; France;USA; UK; Japan; … ]

With no way to denote to the parser in the API where each user starts and ends.

  1. API is a custom Lambda function (i.e. I wrote all of it, so I can make the parser do whatever I want; issue is getting Bubble to send the right data)

I can see the issue in editor and I understand what you mean now.
I’ve made some test.
If you put the two Do a search into a single text field. No issue. So because of that, I was not sure if the issue was related to only a test. So I test using sending data to a requestbin. Same error that you get.

There’s probably a lot of way to achieve what you want, but this can be more complex, depending of your data setting. Are you doing the API call from frontend?

Hi Jici yeah just got a response from Bubble, they’ve confirmed the bug onto the list (but no idea how long it’ll take to fix, so still thinking of a workaround).

In terms of preferred API workflow:

  • We want to calculate some “closeness score” between a user and all other users
  • The user updates something in their profile (i.e. added a new “place visited”, or changes their age)
  • The user’s updated fields are dispatched alongside all the relevant Target User’s fields, the API does the computation, returns the result in terms of a string “1,4,2,1” (one for each target user).
  • (We can then just split this string and read as number so we have a list of numbers.)
  • This list of number is either:
    – Used to update a field (type=list of numbers) in the user’s database (most common case)
    – Used in a custom state to update something dynamically on the page

Functioning workaround:

  • Create a new text variable for each user called “_args”
  • “Update_args” is a backend process that sets each “_args” to be a JSON format constructed from the fields relevant to the computation(s) you want to run. So for example:

Jim Halpert’s _args:

‘funjim@dm.com:{“name”:"Jim Halpert, “likes”:“coffee, paper, baseball”, “dislikes”:“snowballs, paper”}’

^ whole thing is a string

  • (You only need to update this field when a user’s args change, so it’s very efficient if that’s infrequent)
  • When you want to run a computation: Search for users > 's “_args” > :joinbyseparator, wrapped into a JSON format for your API call
  • Partytime

To generalize the use case a bit in Pythoneze: you can do this to effectively run list/dictionary comprehensions, which is very useful. Just familiarize yourself a little bit with AWS Lambda/Google Cloud functions and you can do a lot more with very little extra effort.

3 Likes

@orowa Thank you for this excellent thread. It has solved a massive problem for me because I have almost the same use case you use between Bubble and Lambda. One quick question for you: since the time you posted your functioning workaround, did you learn of any better method to do this? If yes, could you please describe it or link to it if possible?

By the way, since Bubble introduce :format as text, you dont need to do this kind of solution in most case

1 Like