From 758d0f32b1392e0d3aa5b83a1e42c809c2490824 Mon Sep 17 00:00:00 2001 From: Alexandros Milaios Date: Fri, 27 Sep 2024 14:47:34 +0300 Subject: [PATCH] chore: use subdomain in the base url for zendesk chat api. Also, the subdomain will be a required field --- .../connectors/source-zendesk-chat/setup.py | 2 +- .../source_zendesk_chat/source.py | 32 ++++++++++--------- .../source_zendesk_chat/spec.json | 4 +-- .../source_zendesk_chat/streams.py | 13 +++++++- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/airbyte-integrations/connectors/source-zendesk-chat/setup.py b/airbyte-integrations/connectors/source-zendesk-chat/setup.py index 98f9d779a4f4..4f886ac7c179 100644 --- a/airbyte-integrations/connectors/source-zendesk-chat/setup.py +++ b/airbyte-integrations/connectors/source-zendesk-chat/setup.py @@ -5,7 +5,7 @@ from setuptools import find_packages, setup -MAIN_REQUIREMENTS = ["airbyte-cdk", "pendulum"] +MAIN_REQUIREMENTS = ["airbyte-cdk==0.67", "pendulum"] TEST_REQUIREMENTS = ["pytest~=6.1", "pytest-mock", "requests_mock"] diff --git a/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/source.py b/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/source.py index d60bc4292094..e8444c6bffb1 100644 --- a/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/source.py +++ b/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/source.py @@ -34,8 +34,9 @@ def get_auth(self) -> TokenAuthenticator: class SourceZendeskChat(AbstractSource): def check_connection(self, logger, config) -> Tuple[bool, any]: authenticator = ZendeskAuthentication(config).get_auth() + subdomain = config.get("subdomain", None) try: - records = RoutingSettings(authenticator=authenticator).read_records(sync_mode=SyncMode.full_refresh) + records = RoutingSettings(authenticator=authenticator, subdomain=subdomain).read_records(sync_mode=SyncMode.full_refresh) next(records) return True, None except Exception as error: @@ -43,19 +44,20 @@ def check_connection(self, logger, config) -> Tuple[bool, any]: def streams(self, config: Mapping[str, Any]) -> List[Stream]: authenticator = ZendeskAuthentication(config).get_auth() + subdomain = config.get("subdomain", None) return [ - Accounts(authenticator=authenticator), - AgentTimelines(authenticator=authenticator, start_date=config["start_date"]), - Agents(authenticator=authenticator), - Bans(authenticator=authenticator), - Chats(authenticator=authenticator, start_date=config["start_date"]), - Conversions(authenticator=authenticator, start_date=config["start_date"]), - Departments(authenticator=authenticator), - DepartmentEvents(authenticator=authenticator, start_date=config["start_date"]), - Goals(authenticator=authenticator), - Roles(authenticator=authenticator), - RoutingSettings(authenticator=authenticator), - Shortcuts(authenticator=authenticator), - Skills(authenticator=authenticator), - Triggers(authenticator=authenticator), + Accounts(authenticator=authenticator, subdomain=subdomain), + AgentTimelines(authenticator=authenticator, subdomain=subdomain, start_date=config["start_date"]), + Agents(authenticator=authenticator, subdomain=subdomain), + Bans(authenticator=authenticator, subdomain=subdomain), + Chats(authenticator=authenticator, subdomain=subdomain, start_date=config["start_date"]), + Conversions(authenticator=authenticator, subdomain=subdomain, start_date=config["start_date"]), + Departments(authenticator=authenticator, subdomain=subdomain), + DepartmentEvents(authenticator=authenticator, subdomain=subdomain, start_date=config["start_date"]), + Goals(authenticator=authenticator, subdomain=subdomain), + Roles(authenticator=authenticator, subdomain=subdomain), + RoutingSettings(authenticator=authenticator, subdomain=subdomain), + Shortcuts(authenticator=authenticator, subdomain=subdomain), + Skills(authenticator=authenticator, subdomain=subdomain), + Triggers(authenticator=authenticator, subdomain=subdomain), ] diff --git a/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/spec.json b/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/spec.json index 9fd0bba8d7a8..3edf82035b82 100644 --- a/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/spec.json +++ b/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/spec.json @@ -4,7 +4,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "Zendesk Chat Spec", "type": "object", - "required": ["start_date"], + "required": ["start_date", "subdomain"], "additionalProperties": true, "properties": { "start_date": { @@ -18,7 +18,7 @@ "subdomain": { "type": "string", "title": "Subdomain", - "description": "Required if you access Zendesk Chat from a Zendesk Support subdomain.", + "description": "This is your Zendesk subdomain that can be found in your account URL. For example, in https://{MY_SUBDOMAIN}.zendesk.com/, where MY_SUBDOMAIN is the value of your subdomain.", "default": "" }, "credentials": { diff --git a/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/streams.py b/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/streams.py index c27111aa6569..1f1bc4e64882 100644 --- a/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/streams.py +++ b/airbyte-integrations/connectors/source-zendesk-chat/source_zendesk_chat/streams.py @@ -14,13 +14,24 @@ class Stream(HttpStream, ABC): - url_base = "https://www.zopim.com/api/v2/" + def __init__(self, subdomain, **kwargs): + super().__init__(**kwargs) + self.subdomain = subdomain + primary_key = "id" data_field = None limit = 100 + @property + def url_base(self): + # We need to use the subdomain to build the URL. As the zopim API is deprecated and will phase out on 29/10/2024 + # https://developer.zendesk.com/api-reference/live-chat/introduction/ + if self.subdomain: + return f"https://{self.subdomain}.zendesk.com/api/v2/chat/" + return "https://www.zopim.com/api/v2/" + @property def availability_strategy(self) -> Optional["AvailabilityStrategy"]: return None