[text] x

Viewer

  1. import requests
  2. import json
  3.  
  4. # Authentication URL for the Tesco Portal API
  5. auth_url = "https://toolkit.tesco.com/api/login"
  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. payload = {
  11.         "pageNumber": 0,
  12.         "pageSize": 10
  13.     }
  14.  
  15. # Username and password for authentication
  16. username = "[email protected]"
  17. password = "Pladmarch11"
  18.  
  19. # Authentication request data
  20. data = {
  21.     "username": username,
  22.     "password": password
  23. }
  24.  
  25. # Create a session object
  26. session = requests.Session()
  27.  
  28. # Authenticate and receive cookies
  29. auth_response = session.post(auth_url, json=data)
  30.  
  31. # Check if authentication was successful
  32. if auth_response.status_code == 200:
  33.     print("Authentication successful!")
  34.  
  35.     # Fetch JSON response containing report details using the session object
  36.     headers = {'Content-Type': 'application/json', 'Accept': 'application/json, text/plain, */*'}
  37.     response_reports = session.post(url,data=payload,headers=headers)
  38.  
  39.     # Check if fetching JSON response was successful
  40.     if response_reports.status_code == 200:
  41.         # Process the JSON response
  42.         reports_data = response_reports.json()
  43.         print("Report details:", reports_data)
  44.     else:
  45.         print("Failed to fetch report details JSON response." ,response_reports.text)
  46. else:
  47.     print("Authentication failed. Please check your credentials.")

Editor

You can edit this paste and save as new:


File Description
  • x
  • Paste Code
  • 29 Apr-2024
  • 1.45 Kb
You can Share it: