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

Feature to add a filtering options on the API call #145

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Nevsksar
Copy link

Description

When dealing with enterprise workspaces in ClickUp, as ClickUp admins, we often find ourselves having access to multiple workspaces, lists, tasks, and other elements that are not needed in our pipeline. To save resources, processing time, and improve efficiency, it is beneficial for us to have the ability to filter specific elements that we want to fetch.

Noteworthy ClickUp API Bugs

During the development of this project, I encountered some inherent bugs in ClickUp's API. Primarily, these bugs prevented the passing of a single space or list as a parameter. However, a workaround was discovered: by passing the same ID twice, the API would function correctly, and there are not any duplicate values in the API response.

Issues

  1. The following changes have been implemented and work, but they are currently coded to only fetch data from the general settings in the meltano.yml file. Consequently, it is not possible to configure different pipelines for various environments because they are not being correctly read.

For example, when using the command meltano --environment=dev run tap-clickup ..., the configurations are not being applied as expected from the dev envv because it reads only from the common configurations.

Taking this meltano.yml sample, the code always reads "spaces_id" as '90100424497' even when we run it in prod (which in this case should be '90070255202'

version: 1
default_environment: prod
project_id: 8f483ca8-e13c-4abb-8d24-666666666
environments:
- name: prod
  config:
    plugins:
      extractors:
      - name: tap-clickup
        variant: autoidm
        pip_url: tap-clickup
        config:
          workspace_id: 30979640
          spaces_id: '90070255202'
          list_ids: ''
        select:
        - space.name
        - space.id
        - task.*
      loaders:...
plugins:
  extractors:
  - name: tap-clickup
    variant: autoidm
    pip_url: tap-clickup
    config:
      workspace_id: 30979640
      spaces_id: '90100424497'
      list_ids: ''
    select:
    - space.name
    - space.id
    - task.*
  loaders:...
  1. Could not figure out how to correctly add the new setting in the meltano.yml file. At first I was just hardcoding it to the file, then I found out about tap-clickup--autoidm.lock file and in this file I added the new configuration settings to be added when using meltano config tap-clickup -set. But I cannot figure out how to edit this into the projects code, i basically added these configs to the og file:
. . .
    {
      "name": "stream_map_config",
      "kind": "object",
      "label": "Stream Map Config",
      "description": "User-defined config values to be used within map expressions."
    },
    {
      "name": "stream_maps",
      "kind": "object",
      "label": "Stream Maps",
      "description": "Config object for stream maps capability. For more information check out [Stream Maps](https://sdk.meltano.com/en/latest/stream_maps.html)."
    },
	    {
      "name": "workspace_id",
      "kind": "integer",
      "label": "Workspace Id",
      "description": "To limit from which workspace to fetch data pass it's id(https://dev-doc.clickup.com/333/d/h/ad-455845/c464293970a6906)."
    },
	    {
      "name": "spaces_id",
      "kind": "string",
      "label": "Spaces Ids",
      "description": "To limit from which Spaces to fetch data from, pass their ids as a list string Example: spaceid1,spaceid2,ispaced3."
    },
	    {
      "name": "list_ids",
      "kind": "string",
      "label": "Lists Ids",
      "description": "To limit from which Lists to fetch data from, pass their ids as a list string Example: listid1,listid2,listid3."
    }
  ]
}

"workspace_id", th.IntegerType, required=False, description="Example: '20214542" # fetches the data for workspace_id
),
th.Property(
"spaces_id", th.StringType, required=False, description="Example: '[45215477,4547547]" # fetches the data for workspace_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Need this stub as a hack on _sync to force it to use Partitions
# Since this is a child stream we want each team_id to create a request for
# archived:true and archived:false. And we want state to track properly
partitions = []

basepath = "/team/{team_id}/task"
space_ids_param = "&space_ids=" + "&space_ids=".join(map(str, space_ids)) if space_ids else "" #Dinamically create the spaces path to be passed on API call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -16,7 +60,9 @@ class TeamsStream(ClickUpStream):
primary_keys = ["id"]
replication_key = None
schema_filepath = SCHEMAS_DIR / "team.json"
records_jsonpath = "$.teams[*]"
# Necessary because if you have access to multiple workteams, the responses are replicated N times where N = # of worspaces you have access to
records_jsonpath = f"$.teams[?(@.id == {workteamid})]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did they add a new concept of workteamid? Or workspace_id, could you link to that in clickups docs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the structure is Workspace>Space>Folder>List>Task>Subtask

In the app/platform they are called workspaces, but for the API they are called Teams, also there is a feature called "teams" (that group users together) but in the API they call it "group"

image

https://clickup.com/api/clickupreference/operation/CreateTeam/

@@ -4,6 +4,50 @@
import requests
from singer_sdk.helpers.jsonpath import extract_jsonpath
from tap_clickup.client import ClickUpStream
import yaml #added to read information specifying spaces and workspaces
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this needs to go away. Please go through the getting started for Meltano, and read through how singer works.

Adding extra fields to a config block added here https://github.com/AutoIDM/tap-clickup/blob/main/meltano.yml#L6 will pass all of the configs via the config CLI argument (via a json file) to the tap. This is all handled by the config options you altered in tap.py below

# Need this stub as a hack on _sync to force it to use Partitions
# Since this is a child stream we want each team_id to create a request for
# archived:true and archived:false. And we want state to track properly
partitions = []

basepath = "/team/{team_id}/task"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this please

"spaces_id", th.StringType, required=False, description="Example: '[45215477,4547547]" # fetches the data for workspace_id
),
th.Property(
"list_ids", th.StringType, required=False, description="Example: '[454455478,784552187]" # fetches the data for workspace_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@@ -47,6 +47,15 @@ class TapClickUp(Tap):
th.Property(
"api_token", th.StringType, required=True, description="Example: 'pk_12345"
),
th.Property(
"workspace_id", th.IntegerType, required=False, description="Example: '20214542" # fetches the data for workspace_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@@ -220,20 +267,26 @@ class TasksStream(ClickUpStream):

name = "task"
# Date_updated_gt is greater than or equal to not just greater than
path = "/team/{team_id}/task"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below

Copy link
Contributor

@visch visch Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes from line 0 to line 50 need to go away

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants