Lloyd | 2017-12-19 22:00:48 UTC | #1
I'm having an issue using the /api/v2/analytics/queues/observations/query.
I can test the query using the API Explorer and receive a 200-OK with body content.
However when I attempt to make the same request using Python on a Raspberry Pi I'm getting a 400 - Bad Request. I can successfully make GET requests from the Raspberry Pi, so authentication/token wise that is all good.
So I'm presuming I have made a mistake in the request formatting, however other than change the double quotes to single quotes the request body is identical tot he successful one from the API Explorer.
Hoping someone could point out where I've made a mistake - Thanks
PYTHON STARTS HERE
requestHeaders = { 'Content-Type': 'application/json', 'Authorization': mytokentype + ' ' + my_token }
requestBody = { 'filter': { 'type': 'and', 'clauses': [ { 'type': 'or', 'predicates': [ { 'dimension': 'queueId', 'value': 'dc9d3d2d-66c2-4b8e-b9b4-1c289d4521e3' } ] }, { 'type': 'or', 'predicates': [ { 'dimension': 'mediaType', 'value': 'voice' } ] } ] } }
response = requests.post('https://api.mypurecloud.com.au/api/v2/analytics/queues/observations/query', data=requestBody, headers=requestHeaders) if response.statuscode == 200: print 'Got Observations' responseJson = response.json() print json.dumps(responseJson, sortkeys=True, indent=6) else: print 'Failure: ' + str(response.statuscode) + ' - ' + response.reason sys.exit(response.statuscode)
ENDS
Thomas_Larsen | 2017-12-21 10:56:40 UTC | #2
The predicates look wrong, hard to read when it's not formatted, but it should be like this:
{ 'filter': { 'type': 'and', 'predicates': [ { 'type': 'dimension', 'dimension': 'queueId', 'operator': 'matches', 'value': 'dc9d3d2d-66c2-4b8e-b9b4-1c289d4521e3' }, { 'type': 'dimension', 'dimension': 'mediaType', 'operator': 'matches', 'value': 'voice' } ] } }
Lloyd | 2017-12-21 23:42:06 UTC | #3
Thanks for the reply.
Turns out the problem was that I was sending form-encoded data & not json-encoded data. So I added the line:
JSONrequestBody = json.dumps(requestBody)
Then used that in my requests.post:
response = requests.post('https://api.mypurecloud.com.au/api/v2/analytics/queues/observations/query', data=JSONrequestBody, headers=requestHeaders)
And everything worked.
Thanks again
system | 2018-01-21 23:42:17 UTC | #4
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: 2268