Javascript to database

Hi all,
I’m trying to figure out if there is a way to return a datatype from the “server script” action. It clearly lets you pick a datatype that it is returning but I can’t get it to display that returned value in a group which is of the same type. See screenshots here:

As you can see, I’m returning the “Wine” data type but in the subsequent action I’m displaying the returned wine in a group:

But when I run the action, nothing shows up in the group. I have also tried a simpler version of this with just returning text and the group being of type text and that displays fine. It’s either one of two options:

  • Bubble doesn’t allow you to do this
  • The way I am formatting the data being returned is not formatted correctly

Any help would be awesome.

I don’t think you can return a datatype from Server Script. But what you can do is return the datatype’s unique_id. Doing this, you will just have to do a “Search For” in the front-end to have the same result :+1:

1 Like

Thanks for your help here. The only problem is I’m trying to return an api connection data type, not an actual database datatype so there is nothing to do a search on. The obvious next question is then “well then why do you just call the api as you normally would in bubble?”. The reason is because the api is an autocomplete api (algolia) and connecting through the api connector has a short delay making it unusable as an autcomplete feature from a UX point of view.

Thanks again.

I’d like to know this too

Hi @chad
Not sure what exactly you’re trying to do but I found a decent workaround but there are some caveats.

Bubble allows you to run the call client side (the whole reason for the delay in my autocomplete api was that it was running server side which has a second or two delay):

The caveat is that you cannot implement any security in the call (i.e private key in the header) as that will now be available to the public. I am not concerned with security on this one (I doubt there’s too many people that want to access my algolia autocomplete api).

Hope this helps

You can’t include any parameters right? It doesn’t do the job for me anyway. Almost every api call has some kind of authorisation.

I tried a similar version so far without luck but my idea was to initialise a dummy api call with the same json I wanted to return via js

You can provide the authorization as a parameter and any other parameters you want, you just can’t hide them from the public. The only way to hide them is to run the api call server side. If you tick the box for client side, you will just have to set up the call slightly differently to have the auth in the parameters.

When I integrated algolia client side, I was able to perform it, it just means that you can see the api keys in the network requests:

How do you add the tokens without losing the client side checkbox?

Looks like I was incorrect. I was thinking you could send headers as parameters in the url but doesn’t look like you can. As soon as you try to add a header, you use the client side checkbox.