import requests

# TradeTracker API - REST endpoint for product feeds
customer_id = 35058
access_key = 'bf0b9eef0da6caf55fe614518375280fe5c4ecca'

# TradeTracker REST API
base = 'https://ws.tradetracker.com/soap/affiliate'

# Try REST API first
headers = {'Content-Type': 'application/json'}
endpoints = [
    f'https://affiliate.tradetracker.com/feed/product?customerID={customer_id}&passphrase={access_key}',
    f'https://pf.tradetracker.net/?a={customer_id}&p=&q=sneaker&n=10',
]

for url in endpoints:
    try:
        r = requests.get(url, timeout=15, allow_redirects=True)
        print(f'{r.status_code}: {url[:100]}')
        if r.ok:
            text = r.text[:500]
            print(f'  {text}')
    except Exception as e:
        print(f'Error: {e}')
    print()

# TradeTracker product feed download - check for available feeds
# The feed URL format is typically: https://pf.tradetracker.net/?a={affiliateID}&p={campaignID}&fid={feedID}
# Let me try to find available campaigns/feeds
print('--- TradeTracker SOAP API ---')
try:
    import zeep
    client = zeep.Client(wsdl='https://ws.tradetracker.com/soap/affiliate?wsdl')
    # Authenticate
    result = client.service.authenticate(customer_id, access_key)
    print(f'Auth: {result}')
except ImportError:
    print('zeep not installed, trying raw SOAP')
    soap_body = f"""<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:ns="http://schemas.tradetracker.com/affiliate">
  <soap:Body>
    <ns:authenticate>
      <ns:customerID>{customer_id}</ns:customerID>
      <ns:passphrase>{access_key}</ns:passphrase>
    </ns:authenticate>
  </soap:Body>
</soap:Envelope>"""
    r = requests.post('https://ws.tradetracker.com/soap/affiliate', 
                      data=soap_body,
                      headers={'Content-Type': 'text/xml; charset=utf-8',
                               'SOAPAction': 'authenticate'},
                      timeout=15)
    print(f'SOAP Auth: {r.status_code}')
    print(r.text[:500])
