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

Pagination cursor fix. #3

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions tap_klaviyo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand Down
Loading