Transferring an Object from a Plugin to Bubble

Hi,

In my Bubble app, I’ve created a type in the API Connector called “bubble-zone” with the following structure:

{ “id”: 1, “name”: “test”, “color”: “#54df65” }

In my plugin, I have a field called zone-data-type of type “App Type”, and an exposed state array_of_zones of type zone-data-type.

When I try to pass my zone object from the plugin to Bubble, a new item is created in my state, but the properties (id, name, color) are empty.

Here’s the code used in the plugin:

const zoneData = { “id”: 1, “name”: “test”, “color”: “#FFFFFF” }; instance.publishState(‘array_of_zones’, [JSON.stringify(zoneData)]);

I’ve spent the whole day trying to solve this, but I can’t find any information on how to proceed or if there’s a specific structure I need to use for the object.

Thanks for your help!

1 Like

Is the object in the app or the plugin? because the approach you take will be slightly different.

have a look through this article: https://lunchpaillabs.com/blog/working-with-virtual-data-types-in-bubble

thx
The object is created in the plugin and have to be passed to the app

Then the updated code would be

const zoneData = { “_p_id”: 1, “_p_name”: “test”, “_p_color”: “#FFFFFF” };

It needs to have the "_p_" prefix for plugin types

Thanks for your reply, but it still doesn’t work. I must have missed something else.

1 Like

Make sure you’re passing an object (in your example you have JSON.stringify which will pass your object as a single string)

And then @DjackLowCode was right on the money, make sure you use the "_p_" prefix

The prefix for API Connector data is _api_c2_. _p_ is used for Bubble datatypes.

For reference in the plugin (e.g. a datatype created in the Apiconnector - within the plugin), these can be created in the code using the ‘p’ prefix - maybe both api_c2 can be used in this case? :thinking:

Switching to _api_c2_ fixed a similar issue for me in my plugin.

I think I better clarify. If the resulting state App Type is an API Connector datatype, you’ll need to use the api prefix. Both API Connector and DB datatypes are selectable as a plugin “App Type” but the plugin must attach the right prefix accordingly. I just use a boolean in my plugin.

1 Like

Thx a lot !
It finally works.
That was the only thing I hadn’t tried yet :slight_smile:

1 Like