import requests
import sys
sys.path.insert(0, r'C:\Users\Roel\clawd\scripts\demandgen-pipeline')
from config import WEBGAINS_API, PUBLISHER_ID, PROGRAMS, webgains_headers

camp_id = PROGRAMS['manify.nl']['campaign_id']
url = f'{WEBGAINS_API}/auth/publishers/{PUBLISHER_ID}/campaigns/{camp_id}/feeds/products'

# Test with Baskets feed (18588)
params = {'size': 5, 'feeds[]': [18588], 'fields[]': ['title','brand','price','id']}
r = requests.get(url, headers=webgains_headers(), params=params)
print('URL:', r.url[:300])
print('Status:', r.status_code)
d = r.json()
for p in d.get('data', []):
    print(p.get('brand', ''), '|', p.get('title', ''))
print('Pagination:', d.get('pagination'))
print('---')

# Page 2 using search_after
cursor = d.get('pagination', {}).get('search_cursor', '')
if cursor:
    params2 = {'size': 5, 'search_after': cursor, 'fields[]': ['title','brand','price','id']}
    r2 = requests.get(url, headers=webgains_headers(), params=params2)
    print('Page 2 URL:', r2.url[:300])
    d2 = r2.json()
    for p in d2.get('data', []):
        print(p.get('brand', ''), '|', p.get('title', ''))
    print('Pagination:', d2.get('pagination'))
