Skip to Content
ScriptingCustom Filters

Custom Filters

This feature is deprecated and not recommended.

Migration guide

  • Migrate to Inline scripting from Custom Filters.
  • You can reuse the existing custom filters JavaScript files using Import JS Files.
How to use Custom Filters in Inline Scripts:
  • Use the sample code below to import the custom filters JS file in Pre-Request and Post-Request inline scripts.
  • The path should be relative (right-click on the file and select Copy Relative Path) to the workspace if you are using Git Sync. Otherwise, use the full path.
const [ filterName ] = require("thunder-tests/custom-filters.js"); var result = filterName(); console.log(result);

Custom Filters (Deprecated)

  • This feature is deprecated and will be removed in future releases. Please use Import JS Files instead.
  • Custom Filters are a way to extend the functionality of Thunder Client by writing custom JavaScript functions.
Create Custom Filters

Create Custom Filters

Step 1

  • Create a JavaScript file with custom filters
custom-filters.js
const CryptoJS = require("crypto-js"); const { v4: uuid4 } = require("uuid"); async function appendString(input, param1) { // read a file var data = await tc.readFile(input); // execute a command var result = await tc.exec("echo testing"); return `${input} ${data} ${result}`; } function customHmac(input) { console.log("running custom hmac"); var secretValue = tc.getVar("secret"); let encoded = CryptoJS.HmacSHA256(input, secretValue); return encoded.toString(CryptoJS.enc.Base64); } module.exports = [customHmac, appendString];

Step 2

  • Attach custom filter JS files to Collection Settings

col-sets

Step 3

  • Use custom filters in a request

custom-filter-using


Pre-Request Filter

  • Run the custom filter directly in the Pre-Run tab as a pre-request script. This is useful for setting env variables.
Pre Filter
  • This custom filter will not have any arguments and will return no value.
custom-filters.js
function preFilter1() { console.log("set env variable example"); let uuid = uuid4(); // ---- save to active environment tc.setVar("uuidFromScript", uuid); // ---- save to local environment // tc.setVar("uuidFromScript", uuid, "local"); // ---- save to global environment // tc.setVar("uuidFromScript", uuid, "global"); } module.exports = [preFilter1];

Post-Request Filter

  • Run the custom filter directly in the Tests tab as a post-request script.
  • Useful for clean-up tasks after a request or for setting environment variables from the response in advanced use cases.
Post Filter

Scripting Reference

  • For complete scripting reference, please refer to the Scripting section.
Last updated on