Forum Documentation Showcase Pricing Learn more

How to return a list of objects of type 'mytype' from a plugin

Hi ,

I need to return a list of objects of ‘mytype’ from a plugin I am developing to then run a workflow on that list.

  1. an API in the plugin returns a JSON
  2. I need to reformat the JSON and do some data type conversions
  3. then I need to return the object from the plugin to Bubble, to be used by a worklow run on a list of ‘mytype’

Example returned from api
{
“members” :
[
[“John”, “07/14/93”, “25”],
[“Mary”, “07/14/95”, “23”]
]
}

What i would like to return to Bubble
List of Members
[
{
“name” : “John”,
“date” : “1993-07-14T00:00:00.000Z”,
“age” : 25
},
{
“name” : “Mary”,
“date” : “1995-07-14T00:00:00.000Z”,
“age” : 23
}
]

Thank you in advance

Mario

I can see where you want to go with this, but there are some limitations in the plugin mechanism that get in the way.

The plugin can return these objects, if the plugin has the objects are passed in. It cannot modify them or create new ones, but it can however arrange them in a list.

When you setup the API connector, you can choose it to parse the JSON, for which it creates its own types and are kind of inflexible but can be used by Bubble’s expressions.

Or you can choose to return a text blob, then you can pass the text around, and when it gets to javascript you can process it.

The results from the APIs in the plugin are not sent to anywhere else in the plugin, that would need to be done by the app developer.

A way around that is to make API calls from javascript code in the plugin, but then you lose the security of the server making the calls, and the return values could be manipulated by an end user. For some applications this is fine.

Some options here:

  • The app developer passes the data field by field into workflow steps like Create a thing.
  • The plugin returns JSON text and its stored as text, with all the associated problems like not being searchable etc.

I suggest that the implementation you are thinking of is impractical, so try looking at the problem a different way and come up with a different solution.
: )

@mishav explains the problem quite well, but for a rundown of the details of the misery this can cause, see my recent post here:

Essentially if a list of such things is returned, these JSON datatypes and the values that they contain become “read only”.

Oops, wrong post (though relevant). Here’s the one I meant:

tbh, i find bubble quite useless with these limitations
i can literally not use any API i want, the data is unusable and just a list of things unless i can make an API call for exactly what i need, which isn’t possible either because i can not call any arrays
i really have no clue why i should keep using bubble

I’m trying this concept of turning the response from an API call into text. I’m running into the issue of not actually being able convert the text back into a JS object for use in an expression. Is there some special way we’re supposed to reconstitute a geojson text blob for use in an expression? I’ve used JSON.parse(MyDynamicBubbleVariable) and sadly that hasn’t worked.

It’s weird though because when I console.log(MyDynamicBubbleVariable) I can see the array as normal in the Firefox console but it throws an error when I actually try to use it in my function… making it seem like it’s perfectly fine but not at the same time.

image

Here’s a pic of it failing when I use JSON.parse()

image

UPDATE
Here’s the error log in chrome for when the console.log(MyDynamicBubbleVariable) line works but when updateIsochroneLayers(JSON.parse(MyDynamicBubbleVariable)) doesn’t. Says something about the character o

image

But here’s what the json actually looks like and I don’t see any o's at position 1:

Try JSON.parse(JSON.stringify(MyDynamicBubbleVariable))

1 Like

Hmmm, when I call updateIsochroneLayers(JSON.parse(JSON.stringify(MyDynamicBubbleVariable)))
that no longer fails but now it fails in the actual function (which under regular circumstances always works).

image

Showing me that feature is undefined

image

So bizzare… I’ve confirmed the object is now successfully passed into updateIsochroneLayers but something seems to go wrong perhaps starting at the for loop.

Your suggestion did the trick - I realized something funny I was doing elsewhere in my JS made this seem to throw an error in the way I married it to bubble. Thanks so much!