Skip to content

Collection

Collection metadata, variables, headers, and authorization for the request's owning collection. Available when the request belongs to a collection; id is null and name is empty when there is no collection.

Changes to hc.collection.variables, hc.collection.headers, and hc.collection.auth apply to the current send and persist to the collection when the send completes (unlike hc.request.variables.set, which is ephemeral).

hc.collection.auth

Available since v2.0.0

Read and write collection-level authorization for the current send. Same get, set, and update API as hc.request.auth. Changes apply on send and persist to the collection when the send completes.

hc.collection.auth.get()

Available since v2.0.0

Signature:() => object

Returns the same flat auth snapshot shape as hc.request.auth.get().

javascript
var auth = hc.collection.auth.get();
console.log(auth);

hc.collection.auth.set(input)

Available since v2.0.0

Signature:(input: object) => void

Merges collection auth fields from a partial flat object. Persisted to the collection when the send completes.

javascript
hc.collection.auth.set({
  type: "bearer",
  token: hc.collection.variables.get("token"),
});
hc.collection.auth.set({ type: "bearer", token: "{{idToken}}" });

hc.collection.auth.update(field, value)

Available since v2.0.0

Signature:(field: string, value: unknown) => void

Updates a single auth field on the collection configuration. Persisted when the send completes.

javascript
hc.collection.auth.update("type", "none");
hc.collection.auth.update("token", "{{idToken}}");

hc.collection.headers

Available since v2.0.0

Parameter bag for collection-level headers sent with every request in the collection. Header values support {{variable}} syntax. Changes apply to the current send and are persisted to the collection after the send completes. Header keys are matched case-insensitively.

Request-level headers override collection headers when both define the same header name (case-insensitive).

hc.collection.headers.clear()

Available since v2.0.0

Signature:() => void

Removes all collection headers for the remainder of this send. The empty list is persisted when the send completes.

javascript
hc.collection.headers.clear();

hc.collection.headers.get()

Available since v2.0.0

Signature:() => Record<string, string>

Returns a plain object of all enabled collection headers with non-empty keys.

javascript
var headers = hc.collection.headers.get();
console.log(headers["Content-Type"]);

hc.collection.headers.get(key)

Available since v2.0.0

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

Returns the value of the first enabled collection header whose name matches key case-insensitively. Returns undefined if no matching header exists.

javascript
var auth = hc.collection.headers.get("Authorization");

hc.collection.headers.set(entries)

Available since v2.0.0

Signature:(entries: Record<string, unknown>) => void

Batch-upserts multiple collection headers. Persisted to the collection when the send completes.

javascript
hc.collection.headers.set({
  Authorization: "Bearer " + hc.collection.variables.get("token"),
  "X-Api-Version": "2",
});

hc.collection.headers.set(key, value)

Available since v2.0.0

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

Updates an existing enabled collection header or appends a new one. Persisted to the collection when the send completes.

javascript
hc.collection.headers.set(
  "Authorization",
  "Bearer " + hc.collection.variables.get("token")
);

hc.collection.id

Available since v2.0.0

Signature:number | null (read-only)

Storage id of the collection, or null when the request has no collection.

javascript
console.log("Collection id:", hc.collection.id);

hc.collection.name

Available since v2.0.0

Signature:string (read-only)

Display name of the collection the request belongs to. Empty string when the request has no collection.

javascript
console.log("Collection:", hc.collection.name);

hc.collection.variables

Available since v2.0.0

Get and set collection variables for the current send. Collection variables can be referenced elsewhere with {{key}} syntax in URLs, headers, params, body, and script source.

hc.collection.variables.clear(key)

Available since v2.0.0

Signature:(key: string) => void

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

javascript
hc.collection.variables.clear("token");
hc.collection.variables.set("workflow_a.token", "abc");
hc.collection.variables.clear("workflow_a.*");

hc.collection.variables.get(key)

Available since v2.0.0

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

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

javascript
var token = hc.collection.variables.get("token");

hc.collection.variables.set(key, value)

Available since v2.0.0

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

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

javascript
hc.collection.variables.set("token", "abc123");
hc.collection.variables.set("timestamp", String(Date.now()));