Losant Workflow Lab Overview

The Losant Workflow Lab is an interactive tool that provides a set of challenges to solve using Losant’s Visual Workflow Engine. The Workflow Lab is intended to be used by both new and experienced users to grow their workflow development skills.

How the Workflow Lab Works

The Workflow Lab is broken into categorical test suites (Math, Array, etc.) which contain individual tests. Before beginning, users will first create new workflows to solve each Workflow Lab test. Each test is labeled with a test suite and test number. A workflow that has multiple paths to run tests is called a Test Workflow, and is triggered by the Webhook the user will create in the lab. The Workflow Lab’s job is to post a series of input data to one of the users Losant Webhooks. The Webhook, in turn, triggers the Test Workflows you create to calculate and return the expected output value. For example, the first test in this lab (q=1.1) will post two random numbers and will validate that your workflow returns the sum of those two numbers.

Process Overview

Every test includes an example input and example output. The input values (i.e. the 3 and 5 above) will be randomly generated each time the test is run. This prevents you from simply returning a hard-coded output.

The Workflow Lab uses a query parameter to indicate which test question is being asked. The query parameter is q=question_id. For example, when the Workflow Lab invokes the first test in the lab, it will request the following URL:

https://triggers.losant.com/webhooks/your-webhook-id?q=add-two-numbers

This will allow you to use a single Webhook and a single workflow to answer multiple test questions in a test suite. Each test suite in the lab includes 10 to 20 tests each. We recommend using the same Webhook for all tests, but a different workflow for each section. This way you don’t have a giant workflow attempting to answer every test in the lab. The following section provides a high-level architecture for how we recommend you implement your workflows.

Starter Workflows

If you can’t contain your excitement and want to get started right away, we provide Starter Workflows that are prebuilt with everything you need to begin the Workflow Lab. Each Starter Workflow is configured for it’s associated categorical test suite, and contains the following nodes:

  • Webhook Trigger: The Webhook Trigger will fire the Test Workflow when the run button is pressed. Input values are sent from the Workflow Lab in the body of the Webhook request and placed on the payload to allow for calculation and manipulation. Note: you will still need to create your Webhook and select the Webhook Name.
  • Switch Node: The Switch Node is configured with paths for each question in the test suite. The Switch Template ({{ data.query.q }}) is the location of the test number on the payload. Your calculations should be done after the Switch node in the associated path for the test number.
  • Webhook Reply Node: Sending your test answers back to the Workflow Lab is done with a Webhook Reply Node. It is configured without a response code, and sends a formatted result that exists on the payload at working.result.
  • Debug Node: Adding a Debug Node to the end of a workflow path gives more visibility to which path is taken from the Switch Node, as well as the values that exist on the payload.

If you’d like to use the Starter Workflow and are feeling confident, you can head on over to the Workflow Lab and begin. If you’d like to learn more before diving in, keep reading!

Workflow Lab Hello World

If you’re new to the Workflow Lab, this section contains two detailed example tests (q=0.1 and q=0.2) with solutions, and ensures you’ve successfully created a Webhook, connected it to a workflow, and are responding with output data. This workflow will also provide a starting point to quickly add solutions to additional tests from the lab if you choose to create your own Test Workflow.

Setting Up Your Webhook

The Workflow Lab uses a Webhook to send and receive data from your workflow. Each test in the test suite sends input data to your Webhook and expects your processed or calculated data to be returned.

Since data needs to be sent back to the Workflow Lab, be sure to create your Webhook with the “Wait for reply from workflow” option checked, otherwise, your data won’t be sent back and the test will fail. Let’s create a Webhook and name it after the test suite we are working on:

Create a Webhook

Setting Up Your Test Workflow

Create a new workflow to solve your Workflow Lab tests for the example test suite (we recommend creating a workflow for each categorical test suite). A workflow that has multiple paths to run tests is a Test Workflow, and is triggered by the Webhook you just created.

Create a workflow

The Workflow Lab is broken into categorical suites (Math, Array, etc.) that contain individual tests. Each test is labeled with a test suite and test number, so the first test of the Math test suite will be labeled as 1.1, and the second as 1.2. Since these labels correspond to a test within the Workflow Lab, the Test Workflow will need to know which of the tests to run. Adding a Switch Node will allow the workflow to have multiple paths, one for each test in the test suite. Since our example tests are 0.1 and 0.2, we will set up our Switch Node to include those paths. The test number is available on the payload at data.query.q:

Switch Node Path Routing

Example Tests

Our first example test provides two strings, and expects one concatenated string to be returned. We will begin by adding a Debug Node to see how the data runs through the workflow. (Note: it is best practice to include a Debug Node at the end of workflow runs so the final payload is visible.)

By pressing the Run button for test 0.1, we can see the Debug Node Output on the right side.

Switch and Debug Node Output

The payload shows two important values: q, the label for the test, and string, the value we manipulate or perform calculations on. We used q above as the Switch Template in the Switch Node.

Next we will begin manipulating our strings within the 0.1 workflow path. The nodes you use after the Switch Node will depend on the test you are solving, so be sure to familiarize yourself with the Data Nodes. For this example, the test asks that both of our strings be combined. Lucky for us, the String Node has a built-in concatenate operator to do exactly that!

String Node Concatenate Configuration

The Result Path is the location on the payload where your trimmed string will be placed. You can name your path anything; we use the working object to stay as organized as possible and easily distinguish between the original body data and manipulated data.

Now that the original strings have been concatenated to one, we need to send the value back to Losant. Earlier, we told our Webhook to wait for a reply from the workflow. Now, we deliver on that promise with a Webhook Reply Node. We first set the Reply Headers with a Content-Type of application/json. Then set the Reply Body to String Template, and in JSON format pass in the manipulated string (working.result) as the value of result:

Webhook Reply Configuration

Now that the Test Workflow has been set up for example 0.1, we can run the test!

Test Passed!

Our test passed, and our Debug Output shows the original string values as well as the new string that we concatenated.

Final Debug Log

Test 0.2 is yours to conquer, and is a great test for observing the payload and Webhook functionality.

Congratulations! You have successfully completed the Workflow Lab Hello World tests. The workflow you have built will allow you to add tests by creating new test paths in the Switch Node configuration. As the proud new owner of a Test Workflow, you are fully equipped for your mission to complete the Losant Workflow Lab.

Troubleshooting

In case you have trouble completing a test in the Workflow Lab, solutions to each test are available on GitHub. If the test solutions do not address your concern, feel free to post a question in the University section of the Losant Forums. If your Actual Output for a test looks unfamiliar, be sure to check that you are using the correct Webhook and Test Workflow.