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-RequestandPost-Requestinline 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
deprecatedand 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

Step 3
- Use custom filters in a request

Pre-Request Filter
- Run the custom filter directly in the
Pre-Runtab as a pre-request script. This is useful for setting env variables.
- This custom filter will not have any
argumentsand will returnno 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
Teststab 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.
Scripting Reference
- For complete scripting reference, please refer to the Scripting section.
Last updated on