diff --git a/tap_clickup/streams.py b/tap_clickup/streams.py index d4abd88..7577a5f 100644 --- a/tap_clickup/streams.py +++ b/tap_clickup/streams.py @@ -1,6 +1,6 @@ """Stream type classes for tap-clickup.""" from pathlib import Path -from typing import Optional, Any, Dict +from typing import Optional, Any, Dict, Iterable import requests from singer_sdk.helpers.jsonpath import extract_jsonpath from tap_clickup.client import ClickUpStream @@ -24,6 +24,15 @@ def get_child_context(self, record: dict, context: Optional[dict]) -> dict: "team_id": record["id"], } + def get_records(self, context: Optional[dict]) -> Iterable[dict]: + """Return a generator of row-type dictionary objects.""" + # If workspace_ids is empty, null, or nonexistant, default to using the API to + # determine all workspaces/teams. + if "workspace_ids" in self.config and self.config.get("workspace_ids"): + return [{"id": id} for id in self.config.get("workspace_ids")] + else: + return super().get_records(context=context) + class TimeEntries(ClickUpStream): """Time Entries""" @@ -249,6 +258,27 @@ def get_url_params( params["order_by"] = "updated" params["reverse"] = "true" params["date_updated_gt"] = self.get_starting_replication_key_value(context) + + # If list_ids is empty, null, or nonexistant, default to using the API to + if "list_ids" in self.config and self.config.get("list_ids"): + params["list_ids"] = [item for item in self.config.get("list_ids")] + + # If space_ids is empty, null, or nonexistant, default to using the API to + if "space_ids" in self.config and self.config.get("space_ids"): + params["space_ids"] = [item for item in self.config.get("space_ids")] + + if "list_ids" in params and len(params["list_ids"]) == 1: + # To work around the ClickUp API bug that returns an error message stating + # "List ids must be an array" (ECODE: OAUTH_042), we should duplicate the list_id + # when there is only one, as the API requires an array format for list IDs. + params["list_ids"].append(params["list_ids"][0]) + + if "space_ids" in params and len(params["space_ids"]) == 1: + # To work around the ClickUp API bug that returns an error message stating + # "Space ids must be an array" (ECODE: OAUTH_042), we should duplicate the space_id + # when there is only one, as the API requires an array format for space IDs. + params["space_ids"].append(params["space_ids"][0]) + return params def get_next_page_token( diff --git a/tap_clickup/tap.py b/tap_clickup/tap.py index 1c371b3..9fd49a2 100644 --- a/tap_clickup/tap.py +++ b/tap_clickup/tap.py @@ -47,6 +47,15 @@ class TapClickUp(Tap): th.Property( "api_token", th.StringType, required=True, description="Example: 'pk_12345" ), + th.Property( + "workspace_ids", th.ArrayType(th.IntegerType), required=False, description="Example: '[20214542]'" # fetches the data for workspace_id + ), + th.Property( + "space_ids", th.ArrayType(th.IntegerType), required=False, description="Example: '[45215477, 4547547]'" # fetches the data for workspace_id + ), + th.Property( + "list_ids", th.ArrayType(th.IntegerType), required=False, description="Example: '[454455478, 784552187]'" # fetches the data for workspace_id + ), # Removing "official" start_date support re https://github.com/AutoIDM/tap-clickup/issues/118 # th.Property( # "start_date",