[text] J

Viewer

  1. import requests
  2. import json
  3.  
  4. # Authentication URL for the Tesco Portal API
  5. auth_url = "https://toolkit.tesco.com/partner/reports/api/v1/authenticate"
  6.  
  7. # URL to fetch the JSON response containing report details
  8. url = "https://toolkit.tesco.com/partner/reports/api/v1/generated-reports-v2"
  9.  
  10. # Username and password for authentication
  11. username = "your_username"
  12. password = "your_password"
  13.  
  14. # Authentication request data
  15. data = {
  16.     "username": username,
  17.     "password": password
  18. }
  19.  
  20. # Create a session object
  21. session = requests.Session()
  22.  
  23. # Authenticate and receive cookies
  24. auth_response = session.post(auth_url, json=data)
  25.  
  26. # Check if authentication was successful
  27. if auth_response.status_code == 200:
  28.     print("Authentication successful!")
  29.  
  30.     # Fetch JSON response containing report details using the session object
  31.     response_reports = session.post(url)
  32.  
  33.     # Check if fetching JSON response was successful
  34.     if response_reports.status_code == 200:
  35.         # Process the JSON response
  36.         reports_data = response_reports.json()
  37.         print("Report details:", reports_data)
  38.     else:
  39.         print("Failed to fetch report details JSON response.")
  40. else:
  41.     print("Authentication failed. Please check your credentials.")

Editor

You can edit this paste and save as new:


File Description
  • J
  • Paste Code
  • 29 Apr-2024
  • 1.24 Kb
You can Share it: