tshingala | 2022-08-22 17:33:28 UTC | #1
I am getting this error: {'message': 'The request could not be understood by the server due to malformed syntax.', 'code': 'bad.request', 'status': 400, 'contextId': 'e1afaf83-0d02-4ff6-94ff-d56fc94e6154', 'details': [], 'errors': []}
while trying to access this endpoint: POST /api/v2/analytics/users/aggregates/query
requestheaders = { 'Authorization': "Bearer " + token, 'Content-Type': "application/json" } requestbody = { "interval": "2022-08-22T04:00:00.000Z/2022-08-23T04:00:00.000Z", "groupBy": [ "queueId" ], "metrics": [ "nOffered" ] }
When I use the developer tool, I can see the response, even when I do get, I get the desired result
response = requests.get("https://api.cac1.pure.cloud/api/v2/oauth/clients",headers=request_headers)
This doesnt work
response = requests.post("https://api.cac1.pure.cloud/api/v2/analytics/conversations/aggregates/query",data=requestbody,headers=requestheaders)
Really unsure what is the issue here,
Thanks in advance
tim.smith | 2022-08-22 17:49:07 UTC | #2
I don't know what's wrong with your request exactly, but the HTTP payload you're sending is malformed in some way. My guess is that your code is sending request_body as a stringified python object or maybe form data and isn't serializing it to JSON first. The specific error for that correlation ID is "Error code [bad.request] type [JsonParseException] message [Unrecognized token 'interval': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')]"
You could also try using the Python SDK: https://developer.genesys.cloud/devapps/sdk/docexplorer/purecloudpython/AnalyticsApi#post_analytics_conversations_aggregates_query
tshingala | 2022-08-31 17:24:11 UTC | #3
[Solution] Thanks!! @tim.smith I found the solution for my issue..
I was sending requestbody as a data response = requests.post("https://api.cac1.pure.cloud/api/v2/analytics/conversations/aggregates/query",data=requestbody,headers=request_headers)
When I tried sending request_body as JSON ,
response = requests.post("https://api.cac1.pure.cloud/api/v2/analytics/conversations/aggregates/query",json=requestbody,headers=requestheaders)
I got the response I was looking for!!
Posting the solution here for future
system | 2022-09-22 19:02:23 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: 15981