HATO API

The Pigeon Post Office

📘 Manual Sign in Create account

Variable

A variable is a name for a value you want to reuse, such as an address, a customer name, or the result of a request.

Reference a result or field

Start with the Step ID. In the examples below, var1 is the ID of an earlier step on the path the flow actually took. Use a dot to select a field and [0] to select the first item in a list.

For a Letter, use var1.body for the response body and var1.status_code for the status. To read a field from a JSON response, parse the body with to_json.

{{ (var1.body | to_json).remaining_stock }}

A Value exposes its result directly as var1. If it returns a JSON object, select a field such as var1.remaining_stock. The reference var1.output only works if the result itself contains a field named output.

Reserved names

prev.output reads the result of the step that ran immediately before this one. After a Value it gives the value, after a Condition it gives true or false, and after a Letter it lets you select a field such as prev.output.status_code. The first step after Start has no earlier result.

{{ prev.output }}

dir is for saved Directory values, for example dir.base_url. Hato reserves prev and dir, so choose another Step ID.

Use a function

A function changes the value to the left of the pipe. Chain functions to apply them from left to right. The Expression builder shows functions that work with the selected value type.

If name contains Ada with spaces around it, this expression produces ADA.

{{ name | trim | upper }}

If the order has no nickname field, this expression supplies Guest.

{{ order.nickname | default('Guest') }}

Function reference

Square brackets mark optional arguments. Three dots show an argument you can repeat.

Text and defaults

default([fallback], [boolean])

Use a fallback when a value is missing. Pass true as the second argument to also replace empty or false values, including zero.

Example {{ '' | default('Guest', true) }}
Result Guest
upper

Change letters to uppercase.

Example {{ 'Ada' | upper }}
Result ADA
lower

Change letters to lowercase.

Example {{ 'ADA' | lower }}
Result ada
trim([chars])

Remove whitespace from both ends, or remove the specified characters.

Example {{ ' Ada ' | trim }}
Result Ada
ltrim

Remove whitespace from the beginning.

Example {{ ' Ada' | ltrim }}
Result Ada
rtrim

Remove whitespace from the end.

Example {{ 'Ada ' | rtrim }}
Result Ada
replace(old, new)

Replace every occurrence of the old text with the new text.

Example {{ 'red apple' | replace('red', 'green') }}
Result green apple
substr(start, [end])

Take part of a string. With one argument, keep the first N characters. With two, take the characters from start up to the end position.

Example {{ 'pigeon' | substr(1, 4) }}
Result ige

Match and format

re_exists(pattern)

Check whether text matches a regular expression. Returns true or false.

Example {{ 'Order 42' | re_exists('[0-9]+') }}
Result True
re_replace(pattern, replacement)

Replace every match of a regular expression.

Example {{ 'Order 42' | re_replace('[0-9]+', '#') }}
Result Order #
printf(format, [values...])

Format the incoming value and any extra values using a format string.

Example {{ 'order' | printf('%s-%04d', 42) }}
Result order-0042

Encoding

b64enc

Encode text as Base64.

Example {{ 'Hato' | b64enc }}
Result SGF0bw==
b64dec

Decode Base64 back to text.

Example {{ 'SGF0bw==' | b64dec }}
Result Hato
urlenc

Encode a value for a URL query parameter.

Example {{ 'tea + toast' | urlenc }}
Result tea+%2B+toast
urldec

Decode a URL query value back to text.

Example {{ 'tea+%2B+toast' | urldec }}
Result tea + toast

Numbers

round([precision], [method])

Round a number to the requested precision. The methods are common, ceil, and floor.

Example {{ 12.34567 | round(2) }}
Result 12.35
round_up([precision])

Round toward positive infinity at the requested precision.

Example {{ 12.341 | round_up(2) }}
Result 12.35
round_down([precision])

Round toward negative infinity at the requested precision.

Example {{ 12.349 | round_down(2) }}
Result 12.34

Convert values

to_text

Turn a value into text. Text values stay as they are.

Example {{ [1, 2] | to_text }}
Result [1,2]
to_json

Read JSON text or convert an existing value into JSON.

Example {{ '{"total":42}' | to_json }}
Result {"total":42}
to_xml([root_name])

Read XML text or convert structured data to XML. A root name can be supplied when converting JSON.

Example {{ {'name': 'Ada'} | to_xml('customer') }}
Result <customer><name>Ada</name></customer>
to_header

Turn an object or text with header lines into HTTP headers.

Example {{ 'X-Test: value' | to_header }}
Result {"x-test":"value"}

Edit JSON and XML

json_set(path, value)

Set the value of a field or list item at a JSON path.

Example {{ '{"total":42}' | json_set('total', 45) }}
Result {"total":45}
json_delete(path)

Remove a field or list item at a JSON path.

Example {{ '{"total":42,"draft":true}' | json_delete('draft') }}
Result {"total":42}
xml_set(path, value)

Set text or an attribute at an XML path.

Example {{ '<order><total>42</total></order>' | xml_set('total', 45) }}
Result <order><total>45</total></order>
xml_delete(path)

Remove an element or attribute at an XML path.

Example {{ '<order><total>42</total><draft>yes</draft></order>' | xml_delete('draft') }}
Result <order><total>42</total></order>