Monday
I have a triggered task that pulls data from a database and formats the JSON to be returned by an http request.
I added a parameter called 'dataset_name' so users making an api call can select just one record from the database:
I pass the value '_dataset_name' to a filter snap and the API returns the record. This works as expected, when a user queries the endpoint and specifies the dataset_name parameter, they get a JSON with one record.
https://elastic.snaplogic.com/api/1/rest/slsched/feed/.../my_pipeline%20Task?dataset_name=<my_dataset>
However, when a user doesn't specify a parameter, I'd like the API to return all the records in the table. Right now, if you don't specify a "dataset_name" parameter, the http request returns an empty JSON. I'm assuming the issue is with how I've implemented the filtering. Can someone explain what I did wrong?
Solved! Go to Solution.
Tuesday
In the FIlter Snap, you can put a ternary condition, checking if the _dataset_name parameter is empty or not.
If it is empty, process all records, if not, select only that record:
_dataset_name != "" ? db_field == _dataset_name : true
I supoose that you are filtering the data by comparing some input field with the provided parameter from the user. If so, then above expression should help (just replace db_field with the field name you are using for comparing.)
Tuesday
In the FIlter Snap, you can put a ternary condition, checking if the _dataset_name parameter is empty or not.
If it is empty, process all records, if not, select only that record:
_dataset_name != "" ? db_field == _dataset_name : true
I supoose that you are filtering the data by comparing some input field with the provided parameter from the user. If so, then above expression should help (just replace db_field with the field name you are using for comparing.)