Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle optional query parameters in endpoint url #1303

Closed
franky1964 opened this issue Aug 28, 2023 · 8 comments
Closed

How to handle optional query parameters in endpoint url #1303

franky1964 opened this issue Aug 28, 2023 · 8 comments
Labels
feature request New feature or request Priority Implement this asap

Comments

@franky1964
Copy link

Your Team Size Using TC:
Expected team size is: 10-15

Question:
What would be the best way to handle optional query parameters in an endpoint url?

With postman it was very easy by scripting in a "Pre-request Script":
if (pm.variables.get('begin')) pm.request.url.query.add({key: 'from', value: pm.variables.get('begin')});

@franky1964 franky1964 added the question Further information is requested label Aug 28, 2023
@rangav
Copy link
Collaborator

rangav commented Aug 28, 2023

Try using the env variable in query param value e.g {{beginQuery}} and set the initial value to empty or any other value as required.

then in the code

let begin = tc.getVar("begin");
if(begin)
{
   tc.setVar("beginQuery", begin);
}

@rangav
Copy link
Collaborator

rangav commented Aug 28, 2023

We can provide additional API if that helps

Proposal - Updates or Add query param with value

  • If the query param exists - the below with update the value
  • If the query param does not exist, this will add/append the query param to URL
tc.setParam("name", value);

@franky1964
Copy link
Author

franky1964 commented Aug 29, 2023

Hi @rangav,
I did not succceed in using your proposed solution, since the variable cannot be added as a fix query param in request definition.
Therefore I would agree to get an additional API call for adding a query parameter dynamically...

@rangav
Copy link
Collaborator

rangav commented Aug 29, 2023

Sure will add to the roadmap.

@rangav rangav added feature request New feature or request Priority Implement this asap and removed question Further information is requested labels Aug 29, 2023
@rangav
Copy link
Collaborator

rangav commented Sep 1, 2023

This feature is implemented and published to the marketplace, please update to v2.11.0

See all features released
https://github.com/rangav/thunder-client-support/releases/tag/v2.11.0

Please let me know your feedback.

@rangav rangav closed this as completed Sep 1, 2023
@franky1964
Copy link
Author

Hi @rangav,
I checked the new function but the URL isn't enhanced with my dynamically added query params.

I used this code in prescript:

if(status && status !== 'None') {
    tc.setParam("status", status);
    console.log("Set param 'status' to: ", status);
}

Code was executed (as seen in console log) but the Request URL does not have the param 'status' included...

@rangav
Copy link
Collaborator

rangav commented Sep 1, 2023

Let me verify and get back to you.

@rangav
Copy link
Collaborator

rangav commented Sep 1, 2023

There was a bug, Fixed it now.

Please update the extension to - v2.11.1
Update CLI to - v1.4.13 - npm i -g @thunderclient/cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request Priority Implement this asap
Projects
None yet
Development

No branches or pull requests

2 participants