MetricsHub
MetricsHub Community Connectors 1.0.22
-
Home
- Connector Developer Guide Computes 24
encode (Compute)
When To Use
Use encode to apply base64 or url encoding to a single column, row by row, leaving the other columns untouched. The typical use is URL-encoding a device-provided identifier before injecting it into a request path (for example through executeForEachEntryOf and a $1 placeholder), or Base64-encoding a value the target API expects in encoded form.
For HTTP Basic authentication, do not build the credential with encode: use the %{BASIC_AUTH_BASE64} runtime macro[1] directly in the Authorization header. Credential macros (%{USERNAME}, %{PASSWORD}, …) are resolved only in protocol fields (HTTP url/path/header/body, command lines) — a static source does not expand them, so encoding one would Base64 the literal macro text.
Syntax
sources:
volumes:
# One row per volume: <entry>;<name> — names may contain spaces or slashes
type: http
path: /api/volumes
computes:
- type: json2Csv
entryKey: /volumes
properties: /name
- type: encode
column: 2
encoding: url
volumeDetails:
type: http
path: /api/volumes/$2 # safe: the name is URL-encoded
executeForEachEntryOf:
source: ${source::volumes}
concatMethod: json_array
Properties
| Property | Required | Default | Description |
|---|---|---|---|
type |
Yes | None | encode. |
column |
Yes | None | 1-based index of the column to encode. Every row is processed; other columns are left unchanged. |
encoding |
No | None | Encoding to apply: base64 or url. Set it explicitly. |
Table Transformation Example
With column: 2 and encoding: url:
Input
| Entry | Name |
|---|---|
| /volumes[0] | Data/Archive 2024 |
Result
| Entry | Name |
|---|---|
| /volumes[0] | Data%2FArchive%202024 |
With encoding: base64, a value such as admin:S3cr3t! becomes YWRtaW46UzNjcjN0IQ==.
Recommended Pattern
- Apply
encodeas late as possible, after all human-readable filtering and matching computes: encoded values are opaque tokeepOnlyMatchingLines,replace, and friends. - Use
encoding: urlonly on the individual value being substituted into a URL, not on a whole path.
Common Mistakes
- Encoding the wrong column after an upstream compute added or removed columns (indexes are 1-based and shift with the table shape).
- URL-encoding a complete URL or path:
/and?get escaped and the request breaks. Encode only the parameter value. - Running comparisons or translations on a column that was already Base64-encoded; filter first, encode last.
- Confusing direction:
encodeproduces the encoded form; usedecode[2] to recover the original text.
Community Examples
No community connector currently uses encode; the examples above are illustrative.
- [1] ../references-and-expressions.html
- [2] ./decode.html
