Return server side action value to element method in plugin

Hello,
I am creating a plugin in which I created an element and server side action.
Server side action is used to make external request and get data(array), now I want to access this data to update/initialize method of the element.

Is there any way to achieve it using coding? Or any other way?

There is no communication between server side actions and elements.
Server side actions return data. If you want to pass that data to an element you need to do it with an action inside a workflow in bubble.
If your request doesn’t have private data you can make it from a client side action of your element. This way you have access to the element’s data object.

Thanks for your reply. Can’t use element action because I request with private data.
Would you please share more how can I pass data to element using workflow?

In any way you prefer using normal bubble workflows and depending on how you organize the logic in your code.
for example let’s assume your plugin element has a field name and your server action returns a string:

  • create a custom state of type string
  • set the field name to this custom state
  • in your workflow call the server action
  • use the set state action to set the custom state with the string returned

There are also other ways. Experiment ans see what works for you.

Cheers
Mariano

1 Like

Let me try this. Thanks @dorilama

Hello @dorilama,

The given solution works. I have created field and custom state and received the data into element method.

Now, In server side action- A set workflow to call the server side action on page load. So, every time action will be called on page load. I want to add if condition here, Like if i refresh the page first time and got response from external api then set this response(like in cookie) if it is set then next time request shouldn’t send on page load.
Please guide how I can store response of set flag to restrict server side call form 2nd time on page load?

You should implement that with bubble logic, not with the plugin. You may want to store the data you need in the database and conditionally call your actions based on that.

Is it possible to store data into database from plugin action?

No, it’s not possible, unless you want to use Bubble’s data API and make direct requests to it from your code, but at that point you also need to handle the authorization yourself.

Ok. thanks for reply.
I have a one last question. Which would be the best way to implement SSO(single sign on) by using bubble as sso provider? I want to implement sso to my plugin.

There is a lot of topics about that in the forum. You can search for it and then decide what you like more. :slight_smile: