From d0f839c000236c8ca7eb148d1eecdeb65e4f37db Mon Sep 17 00:00:00 2001 From: Adil Ahmed Date: Thu, 16 May 2024 22:38:23 +0500 Subject: [PATCH] Pagination cursor fix. --- tap_klaviyo/client.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tap_klaviyo/client.py b/tap_klaviyo/client.py index 4b17fab..bc13a98 100644 --- a/tap_klaviyo/client.py +++ b/tap_klaviyo/client.py @@ -13,6 +13,7 @@ from singer_sdk.streams import RESTStream from tap_klaviyo.auth import KlaviyoAuthenticator +from urllib.parse import urlparse, parse_qs class KlaviyoStream(RESTStream): @@ -54,9 +55,16 @@ def get_next_page_token( ) token_link = next(iter(all_matches), None) if token_link: - match = re.search(r"page%5Bcursor%5D=(.*)", token_link) - if match: - return match.group(1) + parsed_url = urlparse(token_link) + # Extract the query parameters + query_params = parse_qs(parsed_url.query) + cursor = query_params.get('page[cursor]') + if cursor: + if len(cursor)>0: + next_page_token = cursor[0] + if next_page_token: + return next_page_token + return None def get_starting_time(self, context): start_date = self.config.get("start_date")