Scripting
Custom Filters

Custom Filters

🚫
This feature is deprecated and not recommended.

Migration guide

  • You can re-use the existing custom filters javascript files using Import JS files.

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 Customer Filters

Create Customer Filters

Step 1

  • Create 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 filters JS files to Collection Settings

col-sets

Step 3

  • Use Custom filters in Request

custom-filter-using


Pre Request Filter

  • Run Custom Filter directly in Pre-Run tab as Pre Request Script, useful to set Env Variables
Pre Filter
  • This Custom Filter will not have any arguments and 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 Custom Filter directly in Tests tab as Post Request Script
  • Useful to do clean-up tasks after request or set environment variables from the response for advanced use cases
Post Filter

Scripting Reference

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