Hi all,
looking for a little advice.
I have created a python script to extract quality details to then be used in PowerBI.
when i use the parameters both in the API explorer and Postman i receive the correct data however when i trigger it using the same parameters in a python script it seems to bypass the date range and return data for 2022 and 2021.
Has anyone experienced this before and any ideas on how to resolve it?
I have included the py script with sensitive data removed:
import requests
import json
import base64
import traceback
import os
from datetime import datetime
import pytz
Constants
CLIENT_ID = ""
CLIENT_SECRET = ""
API_BASE_URL = "https://api.euw2.pure.cloud"
TOKEN_URL = "https://login.euw2.pure.cloud/oauth/token"
def get_access_token():
client_credentials = f"{CLIENT_ID}:{CLIENT_SECRET}"
base64_credentials = base64.b64encode(client_credentials.encode()).decode()
token_response = requests.post(TOKEN_URL, headers={
"Authorization": f"Basic {base64_credentials}"
}, data={
"grant_type": "client_credentials"
})
if token_response.status_code == 200:
return token_response.json().get("access_token")
else:
print("Failed to get access token.")
exit()
def fetch_and_save_data(agent_ids, output_file):
access_token = get_access_token()
headers = {
"Authorization": f"Bearer {access_token}"
}
all_data = []
# Format start and end times in ISO 8601 format
start_time = "2023-08-01T00:55:15Z"
end_time = "2023-08-14T12:55:15Z"
for agent_id in agent_ids:
url = f"{API_BASE_URL}/api/v2/quality/evaluations/query"
params = {
"agentUserId": agent_id,
"expandAnswerTotalScores": True,
"page_size": 25,
"page_number": 1,
"sort_by": "sort_by_example",
"expand": "expand_example",
"start_time": start_time,
"end_time": end_time,
"evaluation_state": ["evaluation_state_example"],
"is_released": True,
"maximum": 56,
"sort_order": "sort_order_example"
}
while True:
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
all_data.extend(data["entities"])
if "nextUri" in data:
url = f"{API_BASE_URL}{data['nextUri']}"
else:
break
else:
print(f"Failed to fetch data for agent {agent_id}. Status code:", response.status_code)
print("Response content:", response.text)
break
try:
output_path = r""
output_full_path = os.path.join(output_path, output_file)
with open(output_full_path, "w") as output_file:
json.dump(all_data, output_file, indent=4)
print("Data saved successfully.")
except Exception as e:
print("Error saving data:", str(e))
traceback.print_exc()
if name == "main":
agent_ids = [
""
]
output_file = "MSI_EvaluationsResults.json"
fetch_and_save_data(agent_ids, output_file)