Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Community,
For an API that i am creating the user can optionally give in query params and i want to be able to loop through the list of params to see if they are not empty and need to be applied. I know i can do this manually in a tJava for example by checking each and every single query param, but i want to know if someone has managed to do this in a dynamical way.
Can we access the list of params that are passed from the tRESTRequest component and use only the ones that are filled with a value?
Thanks in advance
I guess the solution to my question is something like this (still need to remove some braces and comma's from the output):
// store all restRequest data
java.util.Map<String, Object> myMap = ((java.util.Map<String, Object>)globalMap.get("restRequest"));
// store only the query parameters from request
java.util.Map<String, Object> myParams = ((java.util.Map<String, Object>)myMap.get("ALL_QUERY_PARAMS"));
// print the query parameters
System.out.println("All query params: "+ myParams);
where from the last System.out.println we get this output:
All query params: {queryParam1=[01], queryParam2=[abc], queryParam3=[999], queryParam4=[contract1,contract2,contract3]}
Hi
What's the data type or format of the query parameters defined for the API? Can you clarify this with more details?
From my understanding, we can parse the query parameters after tRESTRequest, then decide what to do based on the results using runIf connector.
Regards
Shong
hi Shong,
The data types are mostly String and Integer.
Yes it does not really matter where we process or parse the query params. The only thing we want is to go through the list of query params, chech which ones are filled (could be with a tFilterRow) and then use them to pass into another API call within the same job.
But how to loop through the list after the tFilterRow to retrieve each query param name and value to set it in the next URL?
We usually use tFlowToITerate to iterate each value from the list of query params and build a dynamic URL for another API call. Do you know the usage of tFlowToITerate component?
can you give an example of how you would iterate through the list of query params (without knowing what the variable names are)? Because that is what we are looking for, dynamically iterating that list to fetch the 'filled' (not null/empty) variables and concatenate them for the next URL.
in addition:
i found a variable that has all the query params that are used but for some reason i am not able to fetch only the query params from that variable. i guess it has something to do with my syntax?
when i use below i get for example URI, BASE URI but also all of the query params that are given by consumer
System.out.println("All query params: "+ globalMap.get("restRequest"));
but when i try to take only the query params i get below error
System.out.println("All query params: "+ globalMap.get("restRequest").get("ALL_QUERY_PARAMS"));
I guess the solution to my question is something like this (still need to remove some braces and comma's from the output):
// store all restRequest data
java.util.Map<String, Object> myMap = ((java.util.Map<String, Object>)globalMap.get("restRequest"));
// store only the query parameters from request
java.util.Map<String, Object> myParams = ((java.util.Map<String, Object>)myMap.get("ALL_QUERY_PARAMS"));
// print the query parameters
System.out.println("All query params: "+ myParams);
where from the last System.out.println we get this output:
All query params: {queryParam1=[01], queryParam2=[abc], queryParam3=[999], queryParam4=[contract1,contract2,contract3]}
Great! Thanks for sharing the solution!