Quality Aggregates query not pulling right years data from a python script pull

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)

Hi Gerard,

I would suggest using the python SDK for this, it would make what you're doing a lot easier. You can find the documentation for the python sdk here

Regards,
Declan

If you're making the same request with the same credentials and getting a different result, ensure there aren't any bugs in your code that are malforming the request in some way. Once you've ensured that your code is bug-free, please open a case with Genesys Cloud Care to investigate the issue with the API returning incorrect data; we do not have access to your org's data via the forum to be able to troubleshoot this.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.