Legacy Dev Forum Posts

 View Only

Sign Up

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

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

    Posted 06-05-2025 19:08

    gerardmcglynn | 2023-09-06 14:58:49 UTC | #1

    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

    CLIENTID = "" CLIENTSECRET = "" APIBASEURL = "https://api.euw2.pure.cloud" TOKEN_URL = "https://login.euw2.pure.cloud/oauth/token"

    def getaccesstoken(): clientcredentials = f"{CLIENTID}:{CLIENTSECRET}" base64credentials = base64.b64encode(client_credentials.encode()).decode()

    tokenresponse = requests.post(TOKENURL, headers={ "Authorization": f"Basic {base64credentials}" }, data={ "granttype": "client_credentials" })

    if tokenresponse.statuscode == 200: return tokenresponse.json().get("accesstoken") else: print("Failed to get access token.") exit()

    def fetchandsavedata(agentids, outputfile): accesstoken = getaccesstoken() headers = { "Authorization": f"Bearer {access_token}" }

    all_data = []

    Format start and end times in ISO 8601 format

    starttime = "2023-08-01T00:55:15Z" endtime = "2023-08-14T12:55:15Z"

    for agentid in agentids: url = f"{APIBASEURL}/api/v2/quality/evaluations/query" params = { "agentUserId": agentid, "expandAnswerTotalScores": True, "pagesize": 25, "pagenumber": 1, "sortby": "sortbyexample", "expand": "expandexample", "starttime": starttime, "endtime": endtime, "evaluationstate": ["evaluationstateexample"], "isreleased": True, "maximum": 56, "sortorder": "sortorderexample" }

    while True: response = requests.get(url, headers=headers, params=params)

    if response.statuscode == 200: data = response.json() alldata.extend(data["entities"])

    if "nextUri" in data: url = f"{APIBASEURL}{data['nextUri']}" else: break else: print(f"Failed to fetch data for agent {agentid}. Status code:", response.statuscode) print("Response content:", response.text) break

    try: outputpath = r"" outputfullpath = os.path.join(outputpath, outputfile) with open(outputfullpath, "w") as outputfile: json.dump(alldata, outputfile, indent=4) print("Data saved successfully.") except Exception as e: print("Error saving data:", str(e)) traceback.print_exc()

    if name == "main": agentids = [ "" ] outputfile = "MSIEvaluationsResults.json" fetchandsavedata(agentids, outputfile)


    Declan_ginty | 2023-09-06 15:05:48 UTC | #2

    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


    tim.smith | 2023-09-06 15:11:28 UTC | #3

    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.


    system | 2023-10-06 15:11:50 UTC | #4

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


    This post was migrated from the old Developer Forum.

    ref: 21871