Skip to content

Globals

Get and set app-wide global variables. Values set with hc.globals.set are persisted to Settings → Globals after the send completes (unlike hc.request.variables.set, which is ephemeral).

Global variables can be referenced elsewhere with {{key}} syntax in URLs, headers, params, body, and script source.

hc.globals.clear(key)

Available since v2.0.0

Signature:(key: string) => void

Removes a global variable by exact key, or every key under a namespace.* prefix (see namespaces). Matching keys are deleted from Settings → Globals when the send completes.

javascript
hc.globals.clear("baseUrl");
hc.globals.set("workflow_a.token", "abc");
hc.globals.clear("workflow_a.*");

hc.globals.get(key)

Available since v2.0.0

Signature:(key: string) => string | undefined

Returns the value set during this send (via hc.globals.set) if present; otherwise returns the merged runtime variable value (global, collection, and environment). Returns undefined if the key is not set.

javascript
var baseUrl = hc.globals.get("baseUrl");

hc.globals.set(key, value)

Available since v2.0.0

Signature:(key: string, value: string) => void

Sets a global variable for the remainder of this send and persists it to app settings when the send completes. Values are coerced to strings. New keys are added with an empty default and share: false.

javascript
hc.globals.set("baseUrl", "https://api.example.com");