Skip to content

Request

Read and write the outgoing request. Available in both pre- and post-request scripts. Changes made in pre-request scripts affect the request that is sent; changes in post-request scripts do not re-send the request.

hc.request.auth

Available since v2.0.0

Read and write request-level authorization for the current send. Available in pre- and post-request scripts. Changes from pre-request scripts affect the outgoing request for this send only — they are not persisted to the saved request (same as hc.request.headers and hc.request.params). Use the Authorization tab or save credentials in variables when you need durable configuration.

When request auth type is None, collection authorization still applies at send time. See Making requests — Authorization.

hc.request.auth.get()

Available since v2.0.0

Signature:() => object

ParameterTypeDescription
none{ type: 'none' }
basic{ type: 'basic', username, password }
bearer{ type: 'bearer', token }
oauth2{ type: 'oauth2', tokenUrl, clientId, clientSecret, scope, audience, clientAuth }

Returns a plain snapshot of the current auth configuration. Shape depends on auth type:

type Fields
none { type: 'none' }
basic { type: 'basic', username, password }
bearer { type: 'bearer', token }
oauth2 { type: 'oauth2', tokenUrl, clientId, clientSecret, scope, audience, clientAuth }

hc.request.auth.set(input)

Available since v2.0.0

Signature:(input: object) => void

Merges auth fields from a partial flat object onto the current configuration. Switching type preserves credential values stored for other types (matching the Authorization tab). Supported fields: type, token, username, password, tokenUrl, clientId, clientSecret, scope, audience, clientAuth (body or header).

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

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

Available since v2.0.0

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

Updates a single auth field. Same field names as set.

javascript
hc.request.auth.update("token", "new-token");
hc.request.auth.update("type", "none");

hc.request.body

Available since v2.0.0

Signature:string (get/set)

Request body as text. Setters coerce the value to a string.

javascript
hc.request.body = JSON.stringify({ name: "Ada" });

hc.request.headers

Available since v2.0.0

Parameter bag for the request-level header list (not collection-level headers). Changes affect the outgoing request for this send only — they are not persisted to the saved request. Header keys are matched case-insensitively.

hc.request.headers.clear()

Available since v2.0.0

Signature:() => void

Removes all request-level headers for the remainder of this send.

javascript
hc.request.headers.clear();

hc.request.headers.get()

Available since v2.0.0

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

Returns a plain object of all enabled headers with non-empty keys. Header names are preserved as stored.

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

hc.request.headers.get(key)

Available since v2.0.0

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

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

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

hc.request.headers.set(entries)

Available since v2.0.0

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

Batch-upserts multiple headers. Each key is updated in place or appended as a new enabled row.

javascript
hc.request.headers.set({
  Authorization: "Bearer " + hc.request.variables.get("token"),
  "X-Request-Id": hc.request.variables.get("requestId"),
});

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

Available since v2.0.0

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

Updates the value of an existing enabled header with the same name (case-insensitive), or appends a new enabled header if none exists. Values are coerced to strings.

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

hc.request.method

Available since v2.0.0

Signature:string (get/set)

HTTP method for the request (for example GET, POST).

javascript
hc.request.method = "POST";

hc.request.notes

Available since v2.0.0

Accessor for the request tags and comment fields shown in the Discuss tab when using legacy notes (local collections, or Team Hub without threaded discussions). Changes persist to the saved request when the send completes (when the request has been saved). Tags are normalized the same way as the Discuss tab notes editor.

hc.request.notes.clear()

Available since v2.0.0

Signature:() => void

Clears both tags and comment ('' for each).

javascript
hc.request.notes.clear();

hc.request.notes.get()

Available since v2.0.0

Signature:() => { tags: string, comment: string }

Returns the current tags and comment strings.

javascript
var notes = hc.request.notes.get();
console.log(notes.tags, notes.comment);

hc.request.notes.get(field)

Available since v2.0.0

Signature:(field: 'tags' | 'comment') => string

Returns a single notes field.

javascript
var tags = hc.request.notes.get("tags");

hc.request.notes.set(entries)

Available since v2.0.0

Signature:(entries: { tags?: unknown, comment?: unknown }) => void

Batch-updates one or both notes fields. Omitted fields are left unchanged.

javascript
hc.request.notes.set({
  tags: "smoke, api",
  comment: "Validated by pre-request script",
});

hc.request.notes.set(field, value)

Available since v2.0.0

Signature:(field: 'tags' | 'comment', value: unknown) => void

Updates a single notes field. Values are coerced to strings.

javascript
hc.request.notes.set("comment", "Hello world");

hc.request.params

Available since v2.0.0

Parameter bag for the request query params list. Changes affect the outgoing request for this send only — they are not persisted to the saved request. Param keys are matched case-sensitively.

hc.request.params.clear()

Available since v2.0.0

Signature:() => void

Removes all request query params for the remainder of this send.

javascript
hc.request.params.clear();

hc.request.params.get()

Available since v2.0.0

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

Returns a plain object of all enabled query params with non-empty keys.

javascript
var params = hc.request.params.get();
console.log(params.page);

hc.request.params.get(key)

Available since v2.0.0

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

Returns the value of the first enabled param whose key matches exactly. Returns undefined if no matching param exists.

javascript
var page = hc.request.params.get("page");

hc.request.params.set(entries)

Available since v2.0.0

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

Batch-upserts multiple query params.

javascript
hc.request.params.set({
  page: "2",
  limit: "50",
});

hc.request.params.set(key, value)

Available since v2.0.0

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

Updates an existing enabled param or appends a new one. Values are coerced to strings.

javascript
hc.request.params.set("page", "2");

hc.request.url

Available since v2.0.0

Signature:string (get/set)

Request URL. Setters coerce the value to a string.

javascript
hc.request.url = "https://api.example.com/v1/users";

hc.request.variables

Available since v2.0.0

Get and set variables for the current send (or the current live-page navigation). For HTTP requests, collection / folder / environment / global variables are loaded at the start of the send. For live page PreRequest and PostRequest scripts, the same bag is seeded from the active collection / environment chain plus that live page's own variables (live page keys override on conflict — same precedence as the address bar). Values set with hc.request.variables.set are ephemeral and apply only to the current send or navigation (they are not persisted to the collection or live page).

Variables can be referenced elsewhere with {{key}} syntax in URLs, headers, params, body, and script source. For HTTP sends, script source is substituted before each script runs, so a variable set in an earlier script is available to later scripts and to the outgoing request. Within one live-page navigation, sequential PreRequest (or PostRequest) scripts also see earlier set / clear results via get and replaceIn.

Keys may use dotted namespaces (for example workflow_a.foo) with normal set and get. On every variable bag (hc.request.variables, hc.collection.variables, hc.environment.variables, and hc.globals), clear(key) accepts an exact key or a trailing .* pattern: clear("workflow_a.*") removes every key that starts with workflow_a. (including nested keys such as workflow_a.foo.bar). The bare key workflow_a is not cleared by the pattern. Patterns are prefix-only — there is no full glob language (? or mid-string *).

hc.request.variables.clear(key)

Available since v2.0.0

Signature:(key: string) => void

Removes a variable for the remainder of this send or navigation. Pass an exact key, or a namespace.* pattern to clear every key under that prefix (see namespaces above). Cleared keys return undefined from get and are left unchanged in replaceIn templates. Session-only — not persisted to the collection, environment, globals, or live page.

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

hc.request.variables.get(key)

Available since v2.0.0

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

Returns the session value set during this send or navigation (via hc.request.variables.set) if present; otherwise returns the seeded runtime variable value. Returns undefined if the key is not set.

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

hc.request.variables.replaceIn(template)

Available since v2.0.0

Signature:(template: string) => string

Replaces {{key}} placeholders in a string using the same resolution order as send-time substitution: session values set with hc.request.variables.set, then merged runtime variables (global, collection, folder, and environment chain — plus live-page variables when running live-page scripts), then dynamic variables such as {{$guid}} and {{$randomEmail}}. Filters in the template (for example {{name|trim|upper}}) are applied the same way as at send time. Unknown tokens and unknown filter names are left unchanged. See Variables for the dynamic variable list and Variable filters for every filter.

javascript
hc.request.url = hc.request.variables.replaceIn(
  "https://api.example.com/users/{{$guid}}"
);
console.log(hc.request.variables.replaceIn("Bearer {{token}}"));

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

Available since v2.0.0

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

Sets an ephemeral variable for the remainder of this send or navigation. Values are coerced to strings.

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