import requests, json

customer_id = 35058
access_key = 'bf0b9eef0da6caf55fe614518375280fe5c4ecca'

# Van Arendonk feed - get a sample to check available fields
# Feed ID 17108 based on the DB
url = f'https://pf.tradetracker.net/?a={customer_id}&p=&fid=17108&encoding=utf-8&type=json&limit=5'
print(f'Fetching: {url[:80]}...')

r = requests.get(url, timeout=30)
print(f'Status: {r.status_code}')

if r.ok:
    try:
        data = json.loads(r.text)
        if isinstance(data, list) and len(data) > 0:
            print(f'\nFields available: {list(data[0].keys())}')
            print(f'\nFirst product:')
            print(json.dumps(data[0], indent=2, ensure_ascii=False)[:2000])
        elif isinstance(data, dict):
            print(f'\nKeys: {list(data.keys())}')
            print(json.dumps(data, indent=2, ensure_ascii=False)[:2000])
    except:
        print(f'\nNot JSON. First 1000 chars:')
        print(r.text[:1000])
else:
    print(r.text[:500])
