Parameterize DextCloud Application

In the last article we showed you how to create your first application with DextCloud. The application was useful but needs further updates to become a usable API . The city we were checking the weather for, as well as our email and phone number, were hard-coded in the flow. It means that if we would like to check the forecast for any other place, we would have to modify the flow and re-deploy it. Obviously, this makes the previous application not easily consumable by users / using applications. .

Fortunately, DextCloud supports parametrization of flows. Thanks to this feature, we can pass any parameters at the time of calling our flow.

Let’s start with defining input parameters. We need three parameters:

  1. tonum - a phone number where the weather alert will be texted.
  2. email - an email where the weather description will be send.
  3. city - the city we want to check the weather for.

We will do it by defining input parameters for the API component.

Input Parameters

When we run the flow, these parameters should be passed as query parameters (when a flow is called with either GET, DELETE or PUT HTTP request) or as json (in case of POST requests).

Instead of specifying parameters one by one, it possible to pass a Json object. It may a be very handy when an input to a flow is more complex than several parameters. To pass a Json object, click the checkbox “Advanced (JSON)”.

Since our flow is defined to be called by POST HTTP request, a sample request may look like that:

curl -X POST "https://flow.dextcloud.com/5c90abd186cb15000c9994b0/5c9cb1244597f9000ce50a39/flow/rain-warning" -d '{"tonum": "+48600...","city": "Gdansk,pl", "email|:"...@gmail.com}' -H "content-type:application/json" -H "authorization: Bearer {accessToken}"

You do not have to build the url yourself. After you had deployed the flow, you can open the flow’s details right hand side window and click the button the “API”. Then you will see a generated POST request and a command to run a flow.

Flow Details

Now we are ready for the last step. We need to define parameters in components that will be used instead of hard-coded values. Parameters should be surrounded by hash codes (#). A flow input parameters additionally need to be prefixed with input. We will replace hard-coded London,uk in the HTTP component, with #input.city#. Then the url will look like that:

https://api.openweathermap.org/data/2.5/weather?q=#input.city#&APPID={appId}

If we want to parameterize the email address, we need to do the same thing in the SES component’s contextual menu.

Email Parametrization

Analogical change we make in the Twilio component.

Twilio Parametrization

This was just a simple example how DextCloud flows’ parameterization can be used. But handling parameters in DextCloud is more powerful. We will continue the topic in one the next articles.

All posts