Discuss

Creating Reusable Actions with Server Connect Library

On this page

Overview

Server Connect Library allows you to create reusable actions, which can be included in any of your API Actions:

Screenshot_13|690x430

This way you can define some complex actions once, use input parameters for the values and then execute or include them in different API Actions, when needed.

Using Library Actions

There are two ways of using Library Actions - Include and Exec:

Screenshot_8|690x430

Both of them run the selected Library Action but in different ways.

Include Action

The Include Action allows you to include a Library Action Inline in your API Action. It allows you to pick data from inside the Library Actions - as if they were steps in your API Action.

We will show you a simple example of how this works. First, right clicking Library in the Server Connect panel and select Add Library Item:

Screenshot_14|690x430

Then add name for it:

Screenshot_15|690x430

Let's add a database query in the steps. Right click steps and add a Database Single Query:

Screenshot_12|690x430

Setup the query options:

Screenshot_13|690x430

And Save your Library Action when you are done:

Screenshot_14|690x430

Open your API Action, where you want to include the Library Action and right click steps:

Screenshot_15|690x430

Open Core Actions and Select Include Action:

Screenshot_16|690x430

Then click the Action Picker button:

Screenshot_17|690x430

And select your Library Action:

Screenshot_12|690x430

Now, to demonstrate the ability to pick data from the included action, we just add a set value step, so right click on the include step:

Screenshot_18|690x430

And add Set Value:

Screenshot_19|690x430

Click the dynamic data picker:

Screenshot_20|690x430

And you can see the data from your Library Item available in the picker:

Screenshot_21|690x430

Select the data you need and click the Select button:

Screenshot_22|690x430

Save your API Action:

Screenshot_23|690x430

Then let's run the server action in the browser to preview the results. You can see the data from the Library Action as well as the Set Value step showing what we've selected:

Screenshot_24|690x430

Exec Action

The Exec Action allows you to execute an Library Action as a single/separate action and only get its output data. Using Exec Action you can pass values to the input parameters. A good use case can be defining a complex image manipulation workflow as an Library Action and use input params to control the resize/crop width/height, image url and other options.

We will show you another simple example, this way demonstrating how the Exec Action works: First, right clicking Library in the Server Connect panel and select Add Library Item:

Screenshot_14|690x430

Then add name for it:

Screenshot_15|690x430

Defining Input Parameters

With Exec Action you can use input parameters to your Library Action. This way you can send data from your API Actions to the Library Action, when you execute it.

Let's create an input parameter. Open Input, right click $_PARAM and add new variable:

Screenshot_1|690x430

Add a name to it:

Screenshot_2|690x430

Now we can use this parameter in the steps of the Library Item. For example, we can filter a database query. Right click steps:

Screenshot_3|690x430

Add a Single Database Query:

Screenshot_4|690x430

And setup the query options:

Screenshot_6|690x430

We'll use the parameter we created to filter the query, so open the Conditions tab:

Screenshot_7|690x430

Select the column you'd like to filter by:

Screenshot_8|690x430

Then click the dynamic data picker button:

Screenshot_9|690x430

And select the input parameter we've created:

Screenshot_10|690x430

Click OK:

Screenshot_11|690x430

And save you Library Action:

Screenshot_12|690x430

Then open the API Action you want to execute your Library Action in. Right click steps:

Screenshot_13|690x430

Open Core Actions and select Exec Action:

Screenshot_14|690x430

Click the action picker button:

Screenshot_15|690x430

Select your Library Item and click Select:

Screenshot_16|690x430

Assigning Values to Input Parameters

All your Input Parameters from the Library Action will appear here:

Screenshot_17|690x430

You can use a dynamic or static value. The dynamic value can be any dynamic value available in your API Action - GET or POST Parameters, Session Variables, a Query Result etc.

Screenshot_18|690x430

We enter a static value just for testing purposes:

Screenshot_19|690x430

And then we can preview the results in our browser. You can see the Exec results, as well as the rest of your server action steps (if any):

Screenshot_20|690x430

Conclusion

That's how to use the Library Actions to create reusable actions, which can be included in any of your API Actions. Check this new functionality and let us know what do you think :)