-
In our project, we have to create IDs in the following way:
Generating the random string and attaching a prefix to it are easy, but our problem is that for every request, we have a different prefix. We have almost around 70 such requests. In Postman, we would save that prefix on the request level. Since this is not possible in Thunder Client, we are looking for a workaround and would appreciate any help. So far, the only workable option we have found is making a filter per request in our script file, and calling this filter in the appropriate request. Which means over 70 filters just to have different prefixes per request. Here is a simplified example of our script. What would make our lives easier is if we could use parameters with filters. Is this a feature you could consider adding? Or is there perhaps a different solution we have not considered? Thank you for your help. Edit: |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 7 replies
-
Yes you can use paramater with filters, its already supported. But don't use the Pre Request Script feature. Use the filters in Env Variable option. Let me know if this is useful or not? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I am trying to implement exactly same thing listed in this topic and but not able to achieve it. Not sure if I am doing it wrong or it is broken with the version I am using. Steps to Reproduce: function decrypt(stringToDecrypt) {
console.log("String to decrypt = " + stringToDecrypt) //stringToDecrypt is null when called from HTTP header using {{@|decrypt("teststringtodecrypt")}}
// decryption logic goes here and assign the result to 'decryptedValue' variable and return this variable
return decryptedValue;
}
module.exports = [decrypt] From HTTP headers (in the request), I am using below header (in raw format)
This is invoking the "decrypt" function/filter in the external js file as expected but the value (in this case "teststringtodecrypt") is not passed to "decrypt" function/filter. Am I doing something wrong?? Platform: |
Beta Was this translation helpful? Give feedback.
-
Thanks @rangav for the response. I am trying to pass hardcoded text (in this example) I tried below with your suggestion, still see external decrypt.js file function decrypt(stringToDecrypt) {
console.log("String to decrypt = " + stringToDecrypt) //stringToDecrypt is null when called from HTTP header using {{varTemp|decrypt("teststringtodecrypt")}}
// decryption logic goes here and assign the result to 'decryptedValue' variable and return this variable
tc.setVar("varTemp",decryptedValue,"global"); //Added this line to save decryptedValue in varTemp global variable
return decryptedValue; //if variables to be used, this return seems not required.
}
module.exports = [decrypt] |
Beta Was this translation helpful? Give feedback.
-
@rangav Thank you for the help. Adding first argument Regarding your Define the utils like below at collection level //Common functions
utils = {
function1: function(arg1){
// function1 logic goes here
return "function1 result"
},
function12: function(arg1, arg2){
// function2 logic goes here
return "function2 result"
}
} then use |
Beta Was this translation helpful? Give feedback.
-
We launched a new feature - import functions from js files https://github.com/rangav/thunder-client-support/releases/tag/v2.16.0 |
Beta Was this translation helpful? Give feedback.
Example Below
Filter Code:
Update the filter code as needed for your use-case