Legacy Dev Forum Posts

 View Only

Sign Up

Calling API with Python in AWS

  • 1.  Calling API with Python in AWS

    Posted 06-05-2025 19:21

    XAaronYork | 2021-07-29 01:47:56 UTC | #1

    Hi,

    Ive been going through the API workbench available on genesys, and found what I needed: /api/v2/analytics/surveys/aggregates/query { "interval": "2021-07-27T00:00:00/2021-07-28T00:00:00", "groupBy": ["surveyFormId", "conversationId", "surveyId"], "metrics": ["oSurveyQuestionScore"] }

    From that call, I can get the conversation_ids so I could then use:

    /api/v2/quality/conversations/{conversationId}/surveys

    ...where I can plug in conversation_id and extract survey answers.

    Whats the best approach to call these through Python AWS?


    anon11147534 | 2021-07-30 08:17:22 UTC | #2

    Hi Aaron,

    The best way to call our API using Python is with the Python SDK.

    To call /api/v2/quality/conversations/{conversationId}/surveys in the Python SDK you would use the following code:

    # Authenticate firstly
    apiclient = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(os.environ['GENESYS_CLOUD_CLIENT_ID'],
                                                                                              os.environ['GENESYS_CLOUD_CLIENT_SECRET'])
    qualityApi = PureCloudPlatformClientV2.QualityApi(apiclient)
    surveys = qualityApi.get_quality_conversation_surveys(conversation_id) # conversation_id initialised elsewhere

    The following documentation shows the method in greater detail: https://developer.genesys.cloud/api/rest/client-libraries/python/QualityApi#---list-survey-----survey-html--get-quality-conversation-surveys-conversation-id-


    XAaronYork | 2021-07-29 19:16:47 UTC | #3

    Hi Ronan, thanks for the reply.

    Ive tried that code and that worked...how should I supply the timestamp parameter for SurveyAggregationQuery?

    interval str Behaves like one clause in a SQL WHERE. Specifies the date and time range of data being queried. Intervals are represented as an ISO-8601 string. For example: YYYY-MM-DDThh:mm:ss/YYYY-MM-DDThh:mm:ss


    anon11147534 | 2021-07-30 08:21:04 UTC | #4

    You would first get a reference to the SurveyAggregationQuery:

    body = PureCloudPlatformClientV2.SurveyAggregationQuery()

    Then set the interval on it:

    body.interval = "2021-07-27T00:00:00/2021-07-28T00:00:00"

    A similar approach can be done for group_by and metrics

    Documentation for SurveyAggregationQuery


    XAaronYork | 2021-08-02 23:25:14 UTC | #5

    Hi Ronan, t hanks for that...not sure if im doing this right. I get almost nothing with the response - pic attached.


    Jerome.Saint-Marc | 2021-08-03 05:12:25 UTC | #6

    Hello,

    You are not setting the "group by" properly in your SurveyAggregationQuery (wrong attribute name).

    It must be body.group_by as described in the SurveyAggregationQuery description.

    Regards,


    system | 2021-09-03 05:13:26 UTC | #7

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


    This post was migrated from the old Developer Forum.

    ref: 11613