How to make a Platform API call using python

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"
}
]
}
]
}
}

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,

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

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

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

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/

Thanks it worked

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