If I have a endpoint /employees which accepts a pa...
# singer-tap-development
k
If I have a endpoint /employees which accepts a parameter department and I have these list of departments coming in either from meltano config file or as a env variable(all departments as comma separated), how would I make the tap to get all departments mentioned in the config file and use them in employees stream?
For now, I used post_process to filter out records that aren't in the list of departments. But, want to know if we can do multiple API calls with the param. Filtering out seems to be a bad thing since I'll be extracting too many records and then filtering. Direct API call with params will definitely make it faster
e
hi @kk. You could use partitions (see also stream partitioning) and the context argument of get_url_params to get those values. So, something like:
Copy code
class MyStream(RESTStream):
    @property
    def partitions(self):
        return [{"department": department} for department in self.config["departments"]]

    def get_url_params(self, context, next_page_token):
        # <https://api.example.com/employees?department=><dept. name>
        return {
            "department": context["department"],
        }
We don't have an example of this in the
partitions
API docs or in the collection of code samples, so if this works for you it'd be great to add your use case as an example 🙂
k
Sure. Thank you. I'll try it out and add if it works
c
I was wondering about how to use partitions to achieve exactly this scenario just yesterday! Impeccable timing! I'll also give this one a try.
l
You can also see a real world example of this in
tap-github
where we go through a list of repositories passed in config, for instance