Skip to content

Commit

Permalink
Pagination cursor fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
xacadil committed May 16, 2024
1 parent a69c820 commit d0f839c
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit d0f839c

Please sign in to comment.