[text] A

Viewer

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

Editor

You can edit this paste and save as new:


File Description
  • A
  • Paste Code
  • 29 Apr-2024
  • 1.34 Kb
You can Share it: