---
updatedAt: 2025-09-17T00:55:39.000Z
agentTools:
  projectIndex: https://metarouter.readme.io/llms.txt
---

# Global Functions Documentation

# Lua Functions Documentation

This document provides a reference for all available Lua functions that can be used in playbooks. Each function is documented with its description, input types, example usage, and expected output. Click on any function name to expand its details.

***

<details><summary>
<b>BASE64_DECODE</b>
</summary>

### Description

BASE64\_DECODE(input) returns decoded string.

### Input Types

string, number, boolean, object, array

### Example Usage

```lua
return BASE64_DECODE("Rk9P")
```

### Output

```
FOO
```

</details>

***

<details><summary>
<b>BASE64_ENCODE</b>
</summary>

### Description

BASE64\_ENCODE(input) returns encoded string.

### Input Types

string, number, boolean, object, array

### Example Usage

```lua
return BASE64_ENCODE("FOO")
```

### Output

```
Rk9P
```

</details>

***

<details><summary>
<b>DECODE_URL_QUERY</b>
</summary>

### Description

DECODE\_URL\_QUERY(input) returns object with query params.

### Input Types

string

### Example Usage

```lua
return DECODE_URL_QUERY("http&colon;//example.com/path?q=value#fragment")
```

### Output

```
{"q":"value"}
```

</details>

***

<details><summary>
<b>FLATTEN</b>
</summary>

### Description

FLATTEN(input, prefix, separator, depth, option) returns flattened object.

### Input Types

object

### Example Usage

```lua
return FLATTEN(input, "prefix", "_", 5, { array_start_index = 1 })
```

### Sample Input

```json
{
	"products": [
		{
		  "name": "Monopoly"
		},
		{
		  "name": "Uno"
		}
	]
}
```

### Output

```
{"prefix_products_1_name":"Monopoly","prefix_products_2_name":"Uno"}
```

</details>

***

<details><summary>
<b>JOIN</b>
</summary>

### Description

JOIN(input, separator) returns the string representation of an array using an optional delimiter.\
Without separator, it returns concatenated value

### Input Types

array

### Example Usage

```lua
return JOIN(input, ", ")
```

### Sample Input

```json
["foo", "bar"]
```

### Output

```
foo, bar
```

</details>

***

<details><summary>
<b>LOWER</b>
</summary>

### Description

LOWER(input) returns lowercase string.

### Input Types

string

### Example Usage

```lua
return LOWER("HI")
```

### Output

```
hi
```

</details>

***

<details><summary>
<b>MAP</b>
</summary>

### Description

MAP(input, function) returns an array with the results of running func once for every element in values.

### Input Types

array

### Example Usage

```lua
return MAP(input.properties.products, function (product)
		    local price = product.price or 0
		    local quantity = product.quantity or 0
		    return price * quantity
		  end)
```

### Sample Input

```json
{
	"properties" : {
		"products" : [
			{"price": 500, "quantity": 1},
			{ "price" : 300, "quantity" :  2 },
			{              "quantity" : 10 },
			{ "price" : 10                 }
		]
	}
}
```

### Output

```
[500,600,0,0]
```

</details>

***

<details><summary>
<b>MILLISECONDS_SINCE_EPOCH</b>
</summary>

### Description

MILLISECONDS\_SINCE\_EPOCH() returns current time with the defined format.

### Example Usage

```lua
return MILLISECONDS_SINCE_EPOCH()
```

</details>

***

<details><summary>
<b>MILLISECONDS_SINCE_EPOCH_FROM_RFC3999</b>
</summary>

### Description

MILLISECONDS\_SINCE\_EPOCH\_FROM\_RFC3999(input) returns time with the defined format.

### Input Types

string

### Example Usage

```lua
return MILLISECONDS_SINCE_EPOCH_FROM_RFC3999("2006-01-02T15:04:05+07:00")
```

### Output

```
1136189045000
```

</details>

***

<details><summary>
<b>OMIT</b>
</summary>

### Description

OMIT(input, property) returns object without the specified property.

### Input Types

object

### Example Usage

```lua
return OMIT(input, 'foo')
```

### Sample Input

```json
{
	"foo": 1,
	"bar": 2,
	"bin": 3
}
```

### Output

```
{"bar":2,"bin":3}
```

</details>

***

<details><summary>
<b>PATH_ESCAPE</b>
</summary>

### Description

PATH\_ESCAPE(input) returns escaped string.

### Input Types

string, number.

### Example Usage

```lua
return PATH_ESCAPE("Hello, playground")
```

### Output

```
Hello%2C%20playground
```

</details>

***

<details><summary>
<b>PATH_UNESCAPE</b>
</summary>

### Description

PATH\_UNESCAPE(input) returns unescaped string.

### Input Types

string, number

### Example Usage

```lua
return PATH_UNESCAPE("Hello%2C%20playground")
```

### Output

```
Hello, playground
```

</details>

***

<details><summary>
<b>PLUCK</b>
</summary>

### Description

PLUCK(input, property) returns an array by selecting a single property from an collection of values.

### Input Types

array

### Example Usage

```lua
return PLUCK(input.properties.products, 'quantity')
```

### Sample Input

```json
{
	"properties": {
		"products": [
			{
			  "quantity": 1
			},
			{
			  "quantity": 2
			}
		]
	}
}
```

### Output

```
[1,2]
```

</details>

***

<details><summary>
<b>QUERY_ESCAPE</b>
</summary>

### Description

QUERY\_ESCAPE(input) returns escaped string.

### Input Types

string, number

### Example Usage

```lua
return QUERY_ESCAPE("/hello/world?a=b&c=d")
```

### Output

```
%2Fhello%2Fworld%3Fa%3Db%26c%3Dd
```

</details>

***

<details><summary>
<b>QUERY_UNESCAPE</b>
</summary>

### Description

QUERY\_UNESCAPE(input) returns unescaped string.

### Input Types

string

### Example Usage

```lua
return QUERY_UNESCAPE("%2Fhello%2Fworld%3Fa%3Db%26c%3Dd")
```

### Output

```
/hello/world?a=b&c=d
```

</details>

***

<details><summary>
<b>REDUCE</b>
</summary>

### Description

REDUCE(input, function) returns value with the results of running func once for every element in values.

### Input Types

array

### Example Usage

```lua
return REDUCE(input, 0, function (memo, o) return memo + (o.id * 2) end)
```

### Sample Input

```json
[
	{
	  "id": 1
	},
	{
	  "id": 2
	},
	{
	  "id": 3
	}
]
```

### Output

```
12
```

</details>

***

<details><summary>
<b>REPLACE</b>
</summary>

### Description

REPLACE(input, existing\_substring, replacement\_string) returns replaced string.

### Input Types

string

### Example Usage

```lua
return REPLACE(true, "tr", "gl")
```

### Output

```
glue
```

</details>

***

<details><summary>
<b>SECONDS_SINCE_EPOCH</b>
</summary>

### Description

SECONDS\_SINCE\_EPOCH() returns current time with the defined format.

### Example Usage

```lua
return SECONDS_SINCE_EPOCH()
```

</details>

***

<details><summary>
<b>SECONDS_SINCE_EPOCH_FROM_RFC3999</b>
</summary>

### Description

SECONDS\_SINCE\_EPOCH\_FROM\_RFC3999(input) returns time with the defined format.

### Input Types

string

### Example Usage

```lua
return MILLISECONDS_SINCE_EPOCH_FROM_RFC3999("2006-01-02T15:04:05+07:00")
```

### Output

```
1136189045000
```

</details>

***

<details><summary>
<b>SPLIT</b>
</summary>

### Description

SPLIT(input, separator, index) returns array with the defined index.

### Input Types

string

### Example Usage

```lua
return SPLIT("1,2,3,4,5", ",", 3)
```

### Output

```
["1","2","3"]
```

</details>

***

<details><summary>
<b>SUBSTRING</b>
</summary>

### Description

SUBSTRING(input, starting\_position, ending\_position) returns extracted part of a string.

### Input Types

string

### Example Usage

```lua
return SUBSTRING("my string", 0, 2)
```

### Output

```
my
```

</details>

***

<details><summary>
<b>SUM</b>
</summary>

### Description

SUM(input) calculates the sum of elements in a given array.

### Input Types

array

### Example Usage

```lua
return SUM(input)
```

### Sample Input

```json
[1, 2, 3]
```

### Output

```
6
```

</details>

***

<details><summary>
<b>TO_BOOL</b>
</summary>

### Description

TO\_BOOL(input) returns boolean.

### Input Types

string, boolean, number

### Example Usage

```lua
return TO_BOOL("              TRUE            \n")
```

### Output

```
true
```

</details>

***

<details><summary>
<b>TO_DATE_TIME</b>
</summary>

### Description

TO\_DATE\_TIME(input, \{ inputFormat = example-based layouts, outputFormat = example-based layouts }) returns string.\
You can refer valid inputFormat and outputFormat from <https://pkg.go.dev/time#pkg-constants>\
Without outputFormat, it follows RFC3339 format

### Input Types

string

### Example Usage

```lua
return TO_DATE_TIME("2020-10-26T18:10:38Z", { inputFormat = "2006-01-02T15:04:05Z07:00", outputFormat = "Mon Jan _2 15:04:05 MST 2006" })
```

### Output

```
Mon Oct 26 18:10:38 UTC 2020
```

</details>

***

<details><summary>
<b>TO_FLOAT</b>
</summary>

### Description

TO\_FLOAT(input) returns number.\
true returns 1 and false returns 0

### Input Types

number, string, boolean

### Example Usage

```lua
return TO_FLOAT("34.4")
```

### Output

```
34.4
```

</details>

***

<details><summary>
<b>TO_ISO_COUNTRY</b>
</summary>

### Description

TO\_ISO\_COUNTRY(input) returns the ISO country code.\
If the country is not found, it returns the original input string.

### Input Types

string

### Example Usage

```lua
return TO_ISO_COUNTRY("Germany")
```

### Output

```
DE
```

</details>

***

<details><summary>
<b>TO_MD5_HASH</b>
</summary>

### Description

TO\_MD5\_HASH(input) returns MD5 hashed string.

### Input Types

string

### Example Usage

```lua
return TO_MD5_HASH("me@example.com")
```

### Output

```
2e0d5407ce8609047b8255c50405d7b1
```

</details>

***

<details><summary>
<b>TO_ROUNDED_INT</b>
</summary>

### Description

TO\_ROUNDED\_INT(input) returns rounded int.

### Input Types

number, string

### Example Usage

```lua
return TO_ROUNDED_INT("12.51")
```

### Output

```
13
```

</details>

***

<details><summary>
<b>TO_SHA256_HASH</b>
</summary>

### Description

TO\_SHA256\_HASH(input) returns SHA256 hashed string.

### Input Types

string

### Example Usage

```lua
return TO_SHA256_HASH("you@example.com")
```

### Output

```
53e6cdc30765aade0129f85e5aeb50124b1d3f5bb9a70373be31e4eb328371e0
```

</details>

***

<details><summary>
<b>TO_STRING</b>
</summary>

### Description

TO\_STRING(input) returns string.

### Input Types

number, boolean, object

### Example Usage

```lua
return TO_STRING({1, 2})
```

### Output

```
[1,2]
```

</details>

***

<details><summary>
<b>TO_TRUNCATED_FLOAT</b>
</summary>

### Description

TO\_TRUNCATED\_FLOAT(input, precision) returns truncated int.

### Input Types

number, string, boolean

### Example Usage

```lua
return TO_TRUNCATED_FLOAT(1.25, 1)
```

### Output

```
1.2
```

</details>

***

<details><summary>
<b>TO_TRUNCATED_INT</b>
</summary>

### Description

TO\_TRUNCATED\_INT(input) returns truncated int.

### Input Types

number, string

### Example Usage

```lua
return TO_TRUNCATED_INT("12.51")
```

### Output

```
12
```

</details>

***

<details><summary>
<b>TRIM</b>
</summary>

### Description

TRIM(input) returns trimmed string.

### Input Types

string

### Example Usage

```lua
return TRIM("   \n hello there   \n")
```

### Output

```
hello there
```

</details>

***

<details><summary>
<b>UPPER</b>
</summary>

### Description

UPPER(input) returns uppercase string.

### Input Types

string

### Example Usage

```lua
return UPPER("hi")
```

### Output

```
HI
```

</details>

***