Skip to main content

Pre Script

The Pre Script block lets you run custom logic before a request is sent.

It executes locally inside Voiden — not on the API endpoint — in an isolated environment. Use it to dynamically prepare the request: generate tokens, update headers, set variables, or add conditional logic.

Voiden supports JavaScript, Python, and Shell (bash).

For a full reference of what you can do inside a script, see the Voiden Scripting.


How to Insert

  1. In your Voiden file, type /pre_script and press Enter.

    pre-script

  2. Add your script logic inside the block.

    pre-done

  3. Run the request with Cmd + Enter (Mac) or Ctrl + Enter (Windows/Linux).

    pre-script-done

  4. View response and assertions in the Response panel and logs in the Script Logs.


What You Can Access

Inside a Pre Script, the voiden.request object is fully writable:

PropertyDescription
voiden.request.urlRequest URL
voiden.request.methodHTTP method
voiden.request.headersRequest headers
voiden.request.bodyRequest body
voiden.request.queryParamsQuery parameters
voiden.request.pathParamsPath parameters

Examples

The following are a few common examples of what you can do inside a Pre Script. Since scripts run in a full Node.js, Python, or bash process, you're not limited to these — you can write any logic you need.

Override a Header

voiden.request.headers = [{ key: "Authorization", value: "Bearer token" }];

Extend Headers Without Overriding

voiden.request.headers.push({ key: "X-Trace", value: "abc" });

Modify the Request Body

voiden.request.body = { name: "Voiden" };

Canceling the Request

You can stop the request from being sent entirely:

voiden.cancel();

Summary

Pre Scripts give you full control over the request before it is sent. Use them to inject auth tokens, transform payloads, add tracing headers, or conditionally cancel requests based on runtime state.