are you doign this for a client side action? i cant figure out how to return the value like is done with the server side action?
No. AFAIK, client-side actions canât return a value. To make values available client-side, creating an element and publishing one or more Exposed States is the approach I take.
-Steve
Thanks for the rapid reply! I just tried the same approach and failed. Iâve been returning lists instead of an object. Works for my needs for now. The server side Firebase auth sdk actions are so slow but I donât know another way to return objects from my outside data calls.
Itâll work for now. Again, thanks for the input!
This is amazing!
Thanks for sharing, and everyone else for making it easier (node module, etc).
My small contribution is that in Step 2 you do not need to add a fake API link. You can just click the Manually Enter API Response button instead.
This means you can skip parts E, F, G and H of Step 2.
Hey guys !
Quick question/update to checker whether things have improved since or not.
Is this still the only available method to return a Key/Value pair object from SSA ?
{
"Key1":"Value1",
"Key2":"Value2",
"Key3":"Value3"
}
PS: The keys and values are parameterized, so unfortunately I canât initialize this object the way in the API connector.
Or alternatively I can pass this object as string and trying to do some magic on the front-end ?
Any suggestion is welcome.
Thanks!
Hey! So to this logic I wouldnât be able to return deep nested Json? I havenât tried anything like the complex example of Json youâve demonstrated with.
@lottemint.md my mind explodes at how you worked this out.
For how I like to build in Bubble itâs a game changer.
@jared.gibb from my experimentation you can return deep nested JSON. Iâm currently working with JSON several layers deep and Bubble handles it perfectly. A great bonus is that for every new layer / object within the JSON, Bubble allows you to refer to it a as a Type of thing in its own right.
For example, if you had a nesting structure like Transaction > Category > Product
where each of those related to an object with fields, when you push the Exposed State to Bubble (if youâre client side) then all three of those objects will be reference-able within Bubble. I.e. you could set a Dropdown Menu to return a Category
Thing, and then refer to the fields relating to the selected category elsewhere in workflows etc.
They show up in App Type fields like this
Sweet! Thanks for sharing to everyone here! I implement this approach for returning data with my plugins and love it!
Sorry for the late reply. As @exception-rambler said, it is possible to use deep nested JSONs.
I found this feature by accident. I was playing around with the custom API object and the JavascriptToBubble (Toolbox) element. I was so excited when I saw when I sent the custom JSON object, and the Bubble read it!
Regarding deep nested JSONs with arrays:
There is an issue when a template has an array of nested JSON.
For instance, param_1.param_2.param_array
. If you send an empty param_array
to Bubble, the Bubble will prompt an error, for instance, cannot get the length of undefined/null
. As I understand, the Bubble engine parses it and trying to get some info about the array.
BTW, the latest version supports chaging prefix
:
So, the default prefix
is _p_
- it is for object templates built by all plugins.
The prefix
- _api_c2_
is for object templates built by API connectors directly in the app.
Do you still have that issue?
I donât think Bubble is that tolerant of mismatches between the JSON contents and the initialized structure to be able to pass empty objects and arrays.
I ended up passing this object as string.
I wish Bubble would have a key/value return type.
I wish Bubble would add a âData Tabâ to the plugin editor to allow for the definition of custom types. This would make initializing API calls very nice because instead of the kind of hacky âManually Specifyâ you could simply pick one of the custom types that were defined.
So one solution would be to call your data API directly inside of the Server Side Actions. For example to create a new record, assuming you pass the home URL in homeurl
, and return only the status
of the POST
:
// Create your thing
var newthing = ...
// Incantation to upload file
var postoptions = {
uri: properties.homeurl + "api/1.1/obj/mything",
method: "POST",
json: newthing
};
// Send post success status
return context.request(postoptions).body;
Remembering to replace mything
in the path with the name of the thing you want to create. The caveat emptor being that your plugin Server Side Action is no longer agnostic to the implementation details of your specific app.
@lottemint.md
@sudsy
@redvivi
Friends, is this approach still working?
I am trying something simple like this on the client side:
{âtexto01â:âabcâ,âtexto02â:âabcâ} ««« My JSON in the API Connector
obj = {"_p_texto01":âABCâ,"_p_texto02":âABCâ};
console.log(obj); ««« Confirm to me that this is an object
instance.publishState(âtemporary_thingâ, obj); ««« I get nothing in the exposed state
I have read all the messages in this post and have gone over everything I have done several times.
- My âcustom_dataâ field is of type âApp Typeâ.
- I have an exposed state âtemporary_thingâ that is of type âas custom_dataâ.
- I select in the element field the data type created in the API Connector.
I tried a lot before I bothered, I tried JSON.stringify and JSON.parsemas and several other things. I ran out of ideas so I decided to ask if this technique still works.
Double check that youâve covered the bases as described in this post and this post.
Thereâs some configuration required by the user via the pluginâs properties panel in order to connect your custom type to the App Type field.
-Steve
I am trying to use this method to populate a drop-down menu with the results of an api call. Hitting my head against a wall here, and I am sure it is because I am a plebe.
Hopefully, this thread is still alive to help me.
Iâve got a database that I can retrieve the value and display attributes of an option set. I want to use those values in a drop down menu in my bubble app located here: Dev-ramcotraininglogger | Bubble Editor
The dropdown field is located in Popup A.
Now here is some background as well as what I have done so far with my plugin.
The response I receive from the database looks like this:
{
"ResponseCode": 200,
"ResponseText": "OK",
"Data": {
"740300008": "Accounting",
"740300005": "Advanced Find / Reporting",
"740300007": "Automation",
"740300000": "Classes",
"740300006": "Committees",
"740300002": "Core",
"740300003": "Dues",
"740300001": "Meetings",
"740300004": "Membership",
"740300009": "Other"
}
}
I am under the impression, that in order to use this values in a dropdown menu, they must be a list of objectsânot a single object as shown above.
So, I thought I would use a series of .replace() functions to restructure the JSON, then pass it to Lottemintâs convert function to prepend the p notation.
I wound up with this:
Reformatted JSON String
{
"ResponseCode": 200,
"ResponseText": "OK",
"Data": [
{
"Value": "740300008",
"Display": "Accounting"
},
{
"Value": "740300005",
"Display": "AdvancedFind/Reporting"
},
{
"Value": "740300007",
"Display": "Automation"
},
{
"Value": "740300000",
"Display": "Classes"
},
{
"Value": "740300006",
"Display": "Committees"
},
{
"Value": "740300002",
"Display": "Core"
},
{
"Value": "740300003",
"Display": "Dues"
},
{
"Value": "740300001",
"Display": "Meetings"
},
{
"Value": "740300004",
"Display": "Membership"
},
{
"Value": "740300009",
"Display": "Other"
}
]
}
Converted to Bubble Object Format
{
"_p_ResponseCode": 200,
"_p_ResponseText": "OK",
"_p_Data": [
{
"_p_Value": "740300008",
"_p_Display": "Accounting"
},
{
"_p_Value": "740300005",
"_p_Display": "AdvancedFind/Reporting"
},
{
"_p_Value": "740300007",
"_p_Display": "Automation"
},
{
"_p_Value": "740300000",
"_p_Display": "Classes"
},
{
"_p_Value": "740300006",
"_p_Display": "Committees"
},
{
"_p_Value": "740300002",
"_p_Display": "Core"
},
{
"_p_Value": "740300003",
"_p_Display": "Dues"
},
{
"_p_Value": "740300001",
"_p_Display": "Meetings"
},
{
"_p_Value": "740300004",
"_p_Display": "Membership"
},
{
"_p_Value": "740300009",
"_p_Display": "Other"
}
]
}
With regards to the api call, I have created it with and without the section here:
{
"_p_ResponseCode": 200,
"_p_ResponseText": "OK",
"_p_Data":
That made no difference.
I also attempted to output the result of the action into an object (both list and nonlist), and I tried to out put the result as text (list and nonlist)
Here is a action code, all the comments are there because I tried several versions of this to see what worked:
function(properties, context) {
const {convert} = require('json-to-bubble-object');
var jstring = properties.json_string
var jstring = jstring.replace('{"ResponseCode":200,"ResponseText":"OK","Data":','');
var jstring = jstring.replace('{','[{');
var jstring = jstring.replace('}}','}]');
var jstring = jstring.replace(/","/gi,'"},{"');
var jstring = jstring.replace(/":"/gi,'","Display":"');
var jstring = jstring.replace(/"7/gi,'"Value":"7');
//var jstring = jstring.replace('[','{"ResponseCode":200,"ResponseText":"OK","Data":[');
//var njobj = JSON.parse(jstring);
//var obj = convert(jstring);
//return {"options_object": obj}
var objlist = convert(jstring);
return {"options_object_list": objlist}
//return {"reformattedjson": jstring}
//var obj = convert(jstring);
//return {"convertedjson": obj}
}
And here is a pic of the properties:
How bad did I screw this up?
You may find this helpful!
Learn more
Tired of struggling with Bubble or APIâs? Need a little functionality thatâs not available yet thru current market plugins?
Are you ready to step-it-up or speed it along? Need some custom code or a plugin built? Contact me today to learn how to book a 1-on-1 session, get your plugin built, or yet freelance building support!