Legacy Dev Forum Posts

 View Only

Sign Up

How to make a Platform API call using python

  • 1.  How to make a Platform API call using python

    Posted 06-05-2025 18:16

    Abhijeet | 2020-03-27 05:59:25 UTC | #1

    Hi Team,

    I am trying to implement the below sample code ,

    https://developer.mypurecloud.com/api/rest/v2/analytics/queue.html

    with post query is like

    POST https://api.mypurecloud.com/api/v2/analytics/queues/observations/query

    BODY

    { "detailMetrics": [ "oInteracting" ], "filter": { "type": "and", "clauses": [ { "type": "or", "predicates": [ { "dimension": "queueId", "value": "c6fc6f57-4c1e-4812-980a-5154f500b5c6" }, { "dimension": "queueId", "value": "ad97882c-2806-4a6e-8a19-ee5531348638" } ] }, { "type": "or", "predicates": [ { "dimension": "mediaType", "value": "voice" }, { "dimension": "mediaType", "value": "chat" } ] } ] } }

    ================

    My Question is which is the following is the correct way to make the call to the API,

    1)instance/api/v2/analytics/queues/observations/query?{ "detailMetrics": [ "oInteracting" ], "filter": { "type": "and", "clauses": [ { "type": "or", "predicates": [ { "dimension": "queueId", "value": "c6fc6f57-4c1e-4812-980a-5154f500b5c6" }, { "dimension": "queueId", "value": "ad97882c-2806-4a6e-8a19-ee5531348638" } ] }, { "type": "or", "predicates": [ { "dimension": "mediaType", "value": "voice" }, { "dimension": "mediaType", "value": "chat" } ] } ] } }

    2)instance/api/v2/analytics/queues/observations/query?body={ "detailMetrics": [ "oInteracting" ], "filter": { "type": "and", "clauses": [ { "type": "or", "predicates": [ { "dimension": "queueId", "value": "c6fc6f57-4c1e-4812-980a-5154f500b5c6" }, { "dimension": "queueId", "value": "ad97882c-2806-4a6e-8a19-ee5531348638" } ] }, { "type": "or", "predicates": [ { "dimension": "mediaType", "value": "voice" }, { "dimension": "mediaType", "value": "chat" } ] } ] } }


    Jerome.Saint-Marc | 2020-03-27 07:28:53 UTC | #2

    Hello,

    I am not sure I understand the question. The Queues Observations Query is based on an HTTP POST, sending the "parameters" in the body (HTTP POST request Body). You can see this here: https://developer.mypurecloud.com/api/rest/v2/analytics/index.html under the " POST /api/v2/analytics/queues/observations/queryQuery" entry

    If you are calling the Platform API directly from python (I mean using a python Web/REST based client/library), you would have to use HTTP POST and pass the data as body of that request.

    Also note that you can use a Platform API SDK that we provide for Python. See here for details: https://developer.mypurecloud.com/api/rest/client-libraries/python/index.html

    There is also a tutorial which explains how to perform the query for queue using the Platform API SDK for Python. See here: https://developer.mypurecloud.com/api/tutorials/number-of-agent-in-queue/?language=python&step=1

    Hope this helps.

    Regards,


    Abhijeet | 2020-03-27 09:18:52 UTC | #3

    Hi Jerome,

    Thanks for the reply.

    I am directly calling Platform API using python "requests' library. Can you please elaborate on, making the call to rest api with the query as parameter?

    Thanks,

    Abhijeet Hivarkar


    Jerome.Saint-Marc | 2020-03-27 09:33:40 UTC | #4

    There is not much I can say. I don't code in python. You have to check the post method in python requests. See here as an example: https://www.w3schools.com/python/ref_requests_post.asp


    Abhijeet | 2020-03-27 11:17:56 UTC | #5

    Hi Jerome,

    I am getting below error,

    https://api.mypurecloud.com/api/v2/analytics/conversations/aggregates/query {"message":"HTTP 415 Unsupported Media Type","code":"unsupported media type","status":415,"contextId":"b031cf7c-cd32-4f49-a931-d57c3b9f84ae","details":[],"errors":[]}

    for any request I am making


    Jerome.Saint-Marc | 2020-03-27 11:37:44 UTC | #6

    Specify/add a "content-type" header set to "application/json". Search "Custom Headers" section on this page to see an example for python requests: https://2.python-requests.org/en/v1.0.4/user/quickstart/


    Abhijeet | 2020-03-27 13:03:52 UTC | #7

    Thanks it worked


    system | 2020-04-27 13:12:04 UTC | #8

    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: 7416