Lenin Mishra
03/17/2023, 6:31 AM# My code
def streams(self, config: Mapping[str, Any]) -> List[Stream]:
"""
TODO: Replace the streams below with your own streams.
:param config: A Mapping of the user input configuration as defined in the connector spec.
"""
# TODO remove the authenticator if not required.
auth = Oauth2Authenticator(
token_refresh_endpoint="https://accounts.zoho.eu/oauth/v2/token",
client_id=config["client_id"],
client_secret=config["client_secret"],
refresh_token=config["refresh_token"],
) # Oauth2Authenticator is also available if you need oauth support
args = {"authenticator": auth,
"organization_id": config["organization_id"],
"date_start": config["date_start"]}
return [Invoices(**args)]
The result is
{
"type": "LOG",
"log": {
"level": "FATAL",
"message": "'access_token'\nTraceback (most recent call last):\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/main.py\", line 13, in <module>\n launch(source, sys.argv[1:])\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/entrypoint.py\", line 131, in launch\n for message in source_entrypoint.run(parsed_args):\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/entrypoint.py\", line 122, in run\n for message in generator:\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py\", line 114, in read\n stream_is_available, error = stream_instance.check_availability(logger, self)\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/core.py\", line 190, in check_availability\n return self.availability_strategy.check_availability(self, logger, source)\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/availability_strategy.py\", line 45, in check_availability\n get_first_record_for_slice(stream, stream_slice)\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/utils/stream_helper.py\", line 38, in get_first_record_for_slice\n return next(records_for_slice)\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/http.py\", line 423, in read_records\n yield from self._read_pages(\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/http.py\", line 439, in _read_pages\n request, response = self._fetch_next_page(stream_slice, stream_state, next_page_token)\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/http.py\", line 453, in _fetch_next_page\n request = self._create_prepared_request(\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/http.py\", line 280, in _create_prepared_request\n return self._session.prepare_request(requests.Request(**args))\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/requests/sessions.py\", line 484, in prepare_request\n p.prepare(\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/requests/models.py\", line 372, in prepare\n self.prepare_auth(auth, url)\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/requests/models.py\", line 603, in prepare_auth\n r = auth(self)\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py\", line 28, in __call__\n request.headers.update(self.get_auth_header())\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py\", line 33, in get_auth_header\n return {\"Authorization\": f\"Bearer {self.get_access_token()}\"}\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py\", line 38, in get_access_token\n token, expires_in = self.refresh_access_token()\n File \"/Users/pylenin/airbyte/airbyte-integrations/connectors/source-zoho-books/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py\", line 99, in refresh_access_token\n return response_json[self.get_access_token_name()], int(response_json[self.get_expires_in_name()])\nKeyError: 'access_token'"
}
}Nataly Merezhuk (Airbyte)
03/17/2023, 4:44 PMBen Church (Airbyte)
03/17/2023, 4:48 PMZohoOauth2Authenticator which inherits from Oauth2Authenticator
https://github.com/airbytehq/airbyte/blob/master/airbyte-integrations/connectors/source-zoho-crm/source_zoho_crm/auth.py
Reading the comment left behind its because Zoho wants the OAuth params via URL params, not via the request payload.
For reference you can see how its used here
https://github.com/airbytehq/airbyte/blob/master/airbyte-integrations/connectors/source-zoho-crm/source_zoho_crm/api.py#L48Ben Church (Airbyte)
03/17/2023, 4:49 PMLenin Mishra
03/20/2023, 3:53 PM