Skip to main content

Workflow Lab Exercises

The Losant Workflow Lab is an interactive training 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 Losant Developers to grow their workflow development skills.

If you're new to the Workflow Lab, please review the Workflow Lab Overview before continuing. If you need help, please see the Troubleshooting section below.

Running Tests

Each test will trigger a Losant Webhook with input data. Your workflow is expected to reply to the Webhook with the correct output data.

Next to the name of each test and test suites, you'll see a small "Run" button. While you're solving each test, it's recommended you use these to run just the specific test or test suite you're working on. If you think you've got everything solved and want to run the entire lab, you can do so with the button below:

Math

Welcome to your first suite. Each question in this test suite involves solving math questions using a variety of functionality within Losant's Workflow Engine.

The Starter Workflow for this test suite is available here.

For each test in this suite, the input data will be POSTed to the URL below. The specific Test ID will be added as a query param (e.g. https://triggers.losant.com/webhooks/your-webhook-id?id=add-two-numbers).

Add Two Random Numbers

Test ID: add-two-numbers

Adding two numbers is a very simple task, but it allows us to get warmed up in the Workflow Engine. The Workflow Engine is all about manipulating the payload, which means you need to know how to access different parts of the payload. Payload paths are dot-separated references to object properties, such as data.body.num1.

In this test, a JSON object containing two random numbers, "num1" and "num2", will be provided to your Webhook. Your workflow should return a JSON object containing a single field, "result", that is the sum of "num1" and "num2".

Resources: Math Node

Example Input

{
"num1": 3,
"num2": 5
}

Example Output

{
"result": 8
}
{
"num1": 7,
"num2": 21
}
{
"result": 28
}

Results

This test has not been run yet.

Add Three Random Numbers

Test ID: add-three-numbers

The Math Node is meant to process expressions. An expression is a combination of string templates and operators that forms a “JavaScript-like” expression.

In this test, a JSON object containing three random numbers, "num1", "num2", and "num3", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the sum of these three numbers.

Resources: Math Node

Example Input

{
"num1": 3,
"num2": 5,
"num3": 40
}

Example Output

{
"result": 48
}
{
"num1": 19,
"num2": 21,
"num3": 2
}
{
"result": 42
}

Results

This test has not been run yet.

Round One Number

Test ID: round-one-number

There will be cases where you'll receive a number from a Device and you'll want it to be rounded for display purposes. The Math Node supports a number of functions. One, in particular, will help you solve this test.

In this test, a JSON object containing one random number, "num", will be provided to your Webhook. Round the number to the closest integer and return a JSON object containing a single field, "result."

Resources: Math Node, Supported Functions

Example Input

{
"num": 4.4
}

Example Output

{
"result": 4
}
{
"num": 90.1
}
{
"result": 90
}

Results

This test has not been run yet.

Fahrenheit to Celsius

Test ID: temperature-conversion

Let's say your device is reporting temperature in Fahrenheit, but you would like to save the data in Celsius. Since the Math Node evaluates expressions, it's great for processing any formulas for data conversion.

In this test, a JSON object containing a random Fahrenheit temperature, "fahrenheit", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the value, converted to Celsius, rounded to the nearest integer.

Resources: Math Node

Example Input

{
"fahrenheit": 50
}

Example Output

{
"result": 10
}
{
"fahrenheit": 100
}
{
"result": 38
}

Results

This test has not been run yet.

Checking for Even Numbers

Test ID: check-for-even-numbers

Alerting based off a value received from a device is one of the top use cases of the Workflow Engine, but this requires some conditional logic.

In this test, a JSON object containing a single random integer, "num", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is true if the number is even and false if the number is odd.

Resources: Conditional Node, Math Node

Example Input

{
"num": 16
}

Example Output

{
"result": true
}
{
"num": 19
}
{
"result": false
}

Results

This test has not been run yet.

Random Number Between Two

Test ID: random-number-between-two

Losant provides a Device Simulator, but it's really common for Losant Developers to use the Workflow Engine to generate random data and report it as device state.

In this test, a JSON object containing two random numbers, "num1" and "num2", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is a random number between "num1" and "num2" (exclusive).

Resources: Random Number Node

Example Input

{
"num1": 3,
"num2": 50
}

Example Output

{
"result": 39
}
{
"num1": 100,
"num2": 500
}
{
"result": 101
}

Results

This test has not been run yet.

Mutate

The Mutate Node is a hidden gem in the Workflow Engine. Most of the actions you build in a workflow will be manipulating the payload in some way, and the Mutate Node allows for direct manipulation of the payload. This series of test will take you through common Mutate Node actions.

The Starter Workflow for this test suite is available here.

For each test in this suite, the input data will be POSTed to the URL below. The specific Test ID will be added as a query param (e.g. https://triggers.losant.com/webhooks/your-webhook-id?id=mutate-add).

Mutate Add

Test ID: mutate-add

If you were going to build a counter using the Workflow Engine (which happens in a future Workflow Lab test), you need to be able to initialize the value of "0" to start counting. This technique is also helpful if you ever need to create values on the payload.

In this test, an empty JSON object will be provided to your Webhook. Return a JSON object containing a single field, "result", that includes an object with a single key of "counter" which has a value of the number 0.

Resources: Mutate Node

Example Input

{}

Example Output

{
"result": {
"counter": 0
}
}

Results

This test has not been run yet.

Mutate Copy and Delete

Test ID: mutate-copy-delete

When using the Workflow Engine, it's helpful to have standards and best practices. Though you can put data anywhere you want on the payload, working is a best practice we settled on at Losant. Everything in working represents data that we are actively manipulating within a workflow. Using working you can always assume that the rest of the payload is untouched, and you may use those values in other nodes without worry.

In this test, you will move and delete things on the payload. A JSON object containing random data and an empty working object will be provided to your Webhook. Return a JSON object with a single field, "result", that contains a copy of the original payload that you received. Then make a second copy of just data and add it to the empty working object in the result. For this second copy, delete the field "deleteMe".

Resources: Mutate Node

Example Input

{
"data": {
"temperature": 97,
"machineFaultCode": 1284,
"deleteMe": "delete me"
},
"working": {}
}

Example Output

{
"result": {
"data": {
"temperature": 97,
"machineFaultCode": 1284,
"deleteMe": "delete me"
},
"working": {
"data": {
"temperature": 97,
"machineFaultCode": 1284
}
}
}
}

Results

This test has not been run yet.

Mutate Move and Add

Test ID: mutate-move-add

Now, that we've added, copied, and removed values, sometimes we may need to move values from one part of the payload to another. This is helpful if you have a deeply nested value (anObject.anotherObject.data.values.moreData) and you would like to get that value to a place on the payload that's easier to work with, like working.data.

In this test, a deeply nested JSON object containing random data at telemetry will be provided to your Webhook. In result, return the same JSON object with telemetry moved under the working object. Also, add a new field to working called text with the value of "I love Losant".

Resources: Mutate Node

Example Input

{
"deeply": {
"nested": {
"object": {
"telemetry": {
"temperature": 97,
"machineFaultCode": 1284
}
}
}
},
"working": {}
}

Example Output

{
"result": {
"deeply": {
"nested": {
"object": {}
}
},
"working": {
"telemetry": {
"temperature": 97,
"machineFaultCode": 1284
},
"text": "I love Losant"
}
}
}

Results

This test has not been run yet.

Array

An array is a list of things. In most IoT applications, you will have to deal with arrays.

Each question in this test suite involves solving Array Node questions using a variety of functionality within Losant's Workflow Engine.

The Starter Workflow for this test suite is available here.

For each test in this suite, the input data will be POSTed to the URL below. The specific Test ID will be added as a query param (e.g. https://triggers.losant.com/webhooks/your-webhook-id?id=add-random-number-array).

Sum an Array of Random Numbers

Test ID: add-random-number-array

When dealing with an array of data, you may want to perform an aggregation on the dataset before you report it as state to Losant. In this test, we are going to sum every element in the array.

A JSON object containing an array of random numbers, "numbers", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the sum of every number in that array.

Resources: Mutate Node, Loop Node, Math Node

Example Input

{
"numbers": [
8,
5,
12,
6
]
}

Example Output

{
"result": 31
}
{
"numbers": [
20,
21,
22,
23
]
}
{
"result": 86
}

Results

This test has not been run yet.

Find Index in Array

Test ID: array-index

Finding the index of an element in an array is a useful practice, and this test allows you to do exactly that.

A JSON object containing a random number, "random", and an array of random numbers, "numbers", will be provided to your Webhook. Return a JSON object containing a single field, "result", with the first index at which "random" exists in the "numbers" array.

Resources: Array Node

Example Input

{
"random": 77,
"numbers": [
44,
37,
52,
18,
60,
86,
77,
41,
12
]
}

Example Output

{
"result": 6
}
{
"random": 10,
"numbers": [
19,
21,
10,
16
]
}
{
"result": 2
}

Results

This test has not been run yet.

Add to Each Element

Test ID: add-to-element

When dealing with an array of data points, there will be cases in which you'll have to manipulate every single element in the array before doing something with the data. This could be converting a list of temperatures in Celsius to Fahrenheit.

A JSON object containing an array of random numbers, "numbers", and a random number, "random", will be provided to your Webhook. Sum "random" with each value in "numbers" and return a JSON object containing a single field, "result", that is a summed array.

Resources: Loop Node

Example Input

{
"random": 7,
"numbers": [
1,
2,
3
]
}

Example Output

{
"result": [
8,
9,
10
]
}
{
"random": 11,
"numbers": [
1,
2,
3
]
}
{
"result": [
12,
13,
14
]
}

Results

This test has not been run yet.

Flatten Array

Test ID: array-flatten

Third-party data comes back in all sorts of ways. Sometimes, you'll get back something like [1, [2, [3], 4], [5]] and you'll just need a flat array: [1, 2, 3, 4, 5].

In this test, a JSON object containing a randomly nested array called "numbers" will be provided to your Webhook. Return a JSON object containing a single field, "result", with a flattened version of that array.

Resources: Array Node

Example Input

{
"numbers": [
44,
[
37
],
[
[
52,
18
],
60,
86
],
77,
41,
[
12
]
]
}

Example Output

{
"result": [
44,
37,
52,
18,
60,
86,
77,
41,
12
]
}
{
"numbers": [
1,
[
2,
[
3
],
4
],
[
5
]
]
}
{
"result": [
1,
2,
3,
4,
5
]
}

Results

This test has not been run yet.

Array Group By

Test ID: array-groupBy

In some cases, data coming into Losant will not be organized in a way that makes it easy to act upon within the Visual Workflow Engine. The Group By method in the Array Node allows data in an array of objects to be grouped by a given payload path. For example, you can use it to sort a list of devices by class.

In this test, a random array of objects called "devices" will be provided to your Webhook. Your workflow should return a JSON object containing a single field, "result", that is an object of devices sorted by their "class."

Resources: Array Node

Example Input

{
"devices": [
{
"id": "rqw3r3",
"name": "Device 1",
"class": "gateway"
},
{
"id": "12398f",
"name": "Device 1",
"class": "standalone"
}
]
}

Example Output

{
"result": {
"gateway": [
{
"id": "rqw3r3",
"name": "Device 1",
"class": "gateway"
}
],
"standalone": [
{
"id": "12398f",
"name": "Device 2",
"class": "standalone"
}
]
}
}

Results

This test has not been run yet.

String

Each question in this test suite involves solving string questions using a variety of functionality within Losant's Workflow Engine.

The Starter Workflow for this test suite is available here.

For each test in this suite, the input data will be POSTed to the URL below. The specific Test ID will be added as a query param (e.g. https://triggers.losant.com/webhooks/your-webhook-id?id=string-concat).

String Concatenation

Test ID: string-concat

In some cases, when data is provided to a workflow from a device, it is sent in separate pieces that need to be assembled. This test is a simple way to combine two strings that the device reported separately.

A JSON object containing two random strings, "string1" and "string2", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is a concatenated string.

Resources: String Node

Example Input

{
"string1": "race",
"string2": "car"
}

Example Output

{
"result": "racecar"
}
{
"string1": "zabijica",
"string2": "ohoco"
}
{
"result": "zabijicaohoco"
}

Results

This test has not been run yet.

String Separation

Test ID: string-separation

Sometimes when data comes back from devices, you'll need to parse only some of the input. This test is a simplified version of a parsing exercise.

A JSON object containing a random even-length string, "string", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the first half of the string.

Resources: Math Node, String Node

Example Input

{
"string": "2242"
}

Example Output

{
"result": "22"
}
{
"string": "rock"
}
{
"result": "ro"
}

Results

This test has not been run yet.

String Split

Test ID: string-split

Data can sometimes come to a workflow in one large string that needs to be divided. The goal of this test is for you to parse the array at "string" into an array of number values.

Your webhook will receive a JSON object containing comma-separated numbers at "string". Return a JSON object containing a single field, "result", that is the parsed array.

Resources: String Node, Loop Node

Example Input

{
"string": "1,1,0,0,1,1,1,0"
}

Example Output

{
"result": [
1,
1,
0,
0,
1,
1,
1,
0
]
}
{
"string": "0,0,0"
}
{
"result": [
0,
0,
0
]
}

Results

This test has not been run yet.

Compare Email

Test ID: compare-email

In many places, you will need to compare values to see if they are equal. In a Losant Experience this could be comparing emails.

In this test, a JSON object containing two random emails, "email1" and "email2", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is true if the emails are equal and false if not. Since they are emails, case should not be enforced.

Resources: String Node, Conditional Node

Example Input

{
"email1": "modbus@example.com",
"email2": "Modbus@example.com"
}

Example Output

{
"result": true
}
{
"email1": "iot@example.com",
"email2": "losant@example.com"
}
{
"result": false
}

Results

This test has not been run yet.

Template Helpers

Templates are Handlebars templates – they are constructed using a payload path that is wrapped in double curly brackets, such as {{foo.bar}}. Handlebars helpers can also mutate a given value in place and print the result. Losant provides many format helpers. For example, the helper add (usage {{add val1 val2}}) will simply cast the two values as numbers and add them. Each question in this test suite involves using format helpers and the skills practiced in previous suites.

The Starter Workflow for this test suite is available here.

For each test in this suite, the input data will be POSTed to the URL below. The specific Test ID will be added as a query param (e.g. https://triggers.losant.com/webhooks/your-webhook-id?id=add-helper).

Add Two Numbers

Test ID: add-helper

In the Math Suite, you added two numbers using the Math Node. But, throughout the Workflow Engine, we support templates. Using helpers, you can add numbers right from within a template. Let's try that out.

A JSON object containing two random numbers, "num1" and "num2", will be provided to your Webhook. Your workflow should return a JSON object containing a single field, "result", that is the sum of "num1" and "num2".

Resources: Format Helpers

Example Input

{
"num1": 3,
"num2": 5
}

Example Output

{
"result": 8
}
{
"num1": 7,
"num2": 21
}
{
"result": 28
}

Results

This test has not been run yet.

Finding Array Length

Test ID: array-length

You may want to know how many data points were returned from your device, and you'll have to count them to find out. This test is about finding the length of an array, let's get started.

A JSON object containing two random arrays, "array1" and "array2", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the summed length of both arrays.

Resources: Math Node, Format Helpers

Example Input

{
"array1": [
46,
27,
62,
17
],
"array2": [
27,
1,
10
]
}

Example Output

{
"result": 7
}
{
"array1": [
19
],
"array2": [
14,
88,
27,
7,
11
]
}
{
"result": 6
}

Results

This test has not been run yet.

Trimming Strings

Test ID: trim-helper

There are a couple of useful tools to keep in your parsing toolkit. Trimming strings can be very useful.

In this test, a JSON object containing a random string, "string", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the string trimmed of all whitespace.

Resources: String Node, Format Helpers

Example Input

{
"string": " abba "
}

Example Output

{
"result": "abba"
}

Results

This test has not been run yet.

Formatting Numbers

Test ID: format-number

Numbers can be difficult to work with if they are reported in the wrong format. Let's say all you needed was your decimal number displayed on a dashboard in dollar format, well then format helpers just came to your rescue.

In this test, a JSON object containing a random number, "number", will be provided to your Webhook. Return a JSON object containing a single field, "result", which is the original number rounded to two decimal places and returned in U.S. English format, which is commas in the thousands position and periods for the decimal position (e.g. 32,564.23).

Resources: Format Helpers, D3 Number Formatting

Example Input

{
"number": 1689.3489
}

Example Output

{
"result": "1,689.35"
}
{
"number": 3.14159265
}
{
"result": 3.14
}

Results

This test has not been run yet.

Formating Dates

Test ID: format-date

Now, let's format dates. When displaying dates in a Losant Experience, there are many ways you might want to format that date. Well, lucky for you, there is a special helper for that.

A JSON object containing one date, "date", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is "date" in the format of 12/05/2020 (Month/Day/Year).

Resources: Format Helpers, Format Strings

Example Input

{
"date": "2099-05-26T11:36:47.206Z"
}

Example Output

{
"result": "05/26/2099"
}
{
"date": "2019-09-06T13:30:52.557Z"
}
{
"result": "09/06/2019"
}

Results

This test has not been run yet.

Get Date Element

Test ID: get-date-element

When parsing dates, there will be times where you will need to parse one element (e.g. day, month, year) from the date and do something with the result. For example, if given the date "12/25/2019" and parsing out only the day, you would receive "25".

A JSON object containing one date, "date", and the element to be parsed "element", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the "element" parsed from the "date".

Resources: Format Helpers, Switch Node, Format Strings

Example Input

{
"date": "2099-05-26T11:36:47.206Z",
"element": "day"
}

Example Output

{
"result": "5"
}
{
"date": "2019-09-06T13:30:52.557Z",
"element": "year"
}
{
"result": "2019"
}
{
"date": "2019-09-06T13:30:52.557Z",
"element": "month"
}
{
"result": "9"
}

Results

This test has not been run yet.

Workflow Storage

Each question in this test suite involves solving Workflow Storage questions.

The Starter Workflow for this test suite is available here.

For each test in this suite, the input data will be POSTed to the URL below. The specific Test ID will be added as a query param (e.g. https://triggers.losant.com/webhooks/your-webhook-id?id=count-workflow-runs).

Counting Workflow Runs

Test ID: count-workflow-runs

This exercise will help familiarize you with Workflow Storage, which is incredibly useful when using the same value in different workflow runs.

Your workflow will be executed multiple times with an empty payload. When you receive a payload that contains a “count” field, you must return the number of times it has been previously executed and reset your counter. This process will be repeated several times. Each time you receive a payload with a “count” field, you must return the number of workflows executed since the previous “count” payload received.

Resources: Storage: Set Value Node, Storage: Get Value Node

Example Input

{
"count": true
}

Example Output

First execution, result ignored
{}
{
"result": {}
}
{}
{
"result": {}
}
{
"count": true
}
{
"result": 2
}

Results

This test has not been run yet.

Counting Two Workflow Runs

Test ID: count-two-workflow-runs

This test is the same as Counting Workflow Runs, but this time, you'll need to keep track of two counters.

Your workflow will be executed multiple times with an payload containing an "id". When you receive a payload that contains a “count” and "id" field, you must return the number of times that "id" has been previously executed and reset your counter. This process will be repeated several times. Each time you receive a payload with a “count” field, you must return the number of workflows executed since the previous “count” payload received.

Resources: Storage: Set Value Node, Storage: Get Value Node

Example Input

{
"count": true,
"id": "a"
}

Example Output

First execution, result ignored
{
"count": true,
"id": "b"
}
First execution, result ignored
{
"id": "b"
}
{
"result": {}
}
{
"id": "a"
}
{
"result": {}
}
{
"count": true,
"id": "b"
}
{
"result": 1
}

Results

This test has not been run yet.

Encoding / Decoding

Each question in this test suite involves encoding and decoding data in various formats using a variety of functionality within the Workflow Engine.

The Starter Workflow for this test suite is available here.

For each test in this suite, the input data will be POSTed to the URL below. The specific Test ID will be added as a query param (e.g. https://triggers.losant.com/webhooks/your-webhook-id?id=decode-json).

Decoding JSON

Test ID: decode-json

It is important for our Workflows to parse incoming JSON, the extremely popular data-interchange format. In this test, you will practice exactly that.

For this JSON decoding exercise, a JSON object with a "raw" field will be provided to your Webhook. The "raw" field contains an unencoded JSON string with two numbers, "num1" and "num2". Return a JSON object containing a single field, "result", that is the sum of these two numbers.

Resources: JSON: Decode Node, Math Node

Example Input

{
"raw": "{\"num1\":5,\"num2\":8}"
}

Example Output

{
"result": 13
}

Results

This test has not been run yet.

Decoding Base64

Test ID: decode-base64

A Base64-encoded string representing binary data is often provided by IoT devices.

For this exercise, a JSON object containing a Base64 encoded string, "value", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the decoded value of that string.

Resources: Format Helpers

Example Input

{
"value": "aGVsbG8="
}

Example Output

{
"result": "hello"
}
{
"value": "d29ybGQ="
}
{
"result": "world"
}

Results

This test has not been run yet.

Encoding Base64

Test ID: encode-base64

In the decoding test, you parsed a Base64-encoded string representing binary data. In this test, your workflow must create a Base64-encoded string.

For this exercise, a JSON object containing a random string, "value", will be provided to your Webhook. Return a JSON object containing a single field, "result", that is the Base64 encoded value of that string.

Resources: Format Helpers, Escaping HTML

Example Input

{
"value": "hello"
}

Example Output

{
"result": "aGVsbG8="
}

Results

This test has not been run yet.

Decoding Hex

Test ID: decode-hex

Binary data can be sent to the cloud in many different formats. For example, Sigfox messages are small and optimized for sensors and are hexadecimal values containing bytes of data. In this test, you will parse a hexadecimal value.

A JSON object with a "raw" field will be provided to your Webhook. The "raw" field will contain two integers (4 bytes each) encoded as little-endian inside a single hex string. Return a JSON object containing two fields, "temperature" and "voltage". The "temperature" value is encoded in the first four bytes of the hex string. The "voltage" value is encoded in the last four bytes of the hex string.

Resources: Function Node

Example Input

{
"raw": "480c"
}

Example Output

{
"result": {
"temperature": 72,
"voltage": 12
}
}

Results

This test has not been run yet.

Decoding XML

Test ID: decode-xml

The Workflow Engine is commonly used to parse data from third-party APIs, which sometimes send data in XML format. In this test, you will build a workflow that parses XML data.

An XML document containing a "Sensor" root tag with three child sensor tags, "Temperature", "Voltage", and "Current" will be provided to your workflow. Each sensor tag will contain two child tags, "Value" and "Threshold". Return a JSON object containing "temperature", "voltage", and "current" fields. Each field is set to true if the corresponding sensor's value is above the associated threshold, and false otherwise.

Resources: HTML/XML Parser Node, Conditional Node or Conditional Block Helpers

Example Input

<?xml version="1.0" encoding="UTF-8"?>
<Sensor>
<Temperature>
<Value>100</Value>
<Threshold>95</Threshold>
</Temperature>
<Voltage>
<Value>12</Value>
<Threshold>14</Threshold>
</Voltage>
<Current>
<Value>15</Value>
<Threshold>30</Threshold>
</Current>
</Sensor>

Example Output

{
"result": {
"temperature": true,
"voltage": false,
"current": false
}
}

Results

This test has not been run yet.

Encoding JWT

Test ID: encode-jwt

JSON Web Tokens are an open, industry standard for representing claims securely between two parties. In this test, you will be creating a JWT Token.

A JSON object containing random "data" (a "string" and "num") and a "secret" will be provided to your Webhook. You workflow needs to return a JSON object containing a single field, "token", that is the encoded JWT token value of "data" using "secret" to sign the token.

Resources: JWT: Create Node

Example Input

{
"data": {
"string": "example",
"num": 4
},
"secret": "SECRET"
}

Example Output

{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdHJpbmciOiJleGFtcGxlIiwibnVtIjo0fQ.tr0A5yGnZq7rE2N-Qow_t35ANyTu2v4eNWEkg7-RqfY"
}

Results

This test has not been run yet.

Validation

Validating input is an important part of any IoT solution. If you're accepting user input from a Losant Experience, you must always ensure that you've received the details that you require and it's formatted correctly. Responding with appropriate codes and messages is also an important part of a well-designed system. This suite contains tests that will require your workflow to implement common validation techniques.

The Starter Workflow for this test suite is available here.

For each test in this suite, the input data will be POSTed to the URL below. The specific Test ID will be added as a query param (e.g. https://triggers.losant.com/webhooks/your-webhook-id?id=required-fields).

Required Fields

Test ID: required-fields

This exercise mimics a user registration request.

A valid registration request will be a JSON object containing "email", "password", "firstName", and "lastName" fields. If any field is missing your webhook must respond with an HTTP Status Code of 400 and a JSON object containing a single field, "error", that contains the message "One or more user fields are missing.". If all fields are supplied, your webhook must respond with an HTTP Status Code of 200 and a JSON object containing a single field, "result", that contains the message "success".

Resources: Validate Payload Node

Example Input

{
"email": "jane@example.com",
"password": "my-password",
"firstName": "Jane"
}

Example Output

{
"error": "One or more user fields are missing."
}
Status Code: 400
{
"email": "jane@example.com",
"password": "my-password",
"firstName": "Jane",
"lastName": "Smith"
}
{
"result": "success"
}
Status Code: 200

Results

This test has not been run yet.

Troubleshooting

If you have trouble completing a test in the Workflow Lab, a Solution Workflow for each test suite is available on GitHub. Each Solution Workflow is Losant's recommended way of solving these problems.

If the Solution Workflows do not address your concern, feel free to post a question in the Workflow Lab section of the Losant Forums.

Common Problems

  • If your "Actual Output" for an test looks unfamiliar, be sure to check that you are triggering the correct Webhook/Workflow. It's possible to have two workflows listening to the same Webhook.
  • The Workflow Lab expects your workflow to return valid JSON. It's important to ensure that within the Webhook Reply Node, you add a header of "Content-Type" and it's set to "application/json".

Was this page helpful?


Still looking for help? You can also search the Losant Forums or submit your question there.