AuditApi - Get Audit results for Transaction ID

Hi All,

I'm working on AuditApi and using the function get_audits_query_transaction_id_results() to get audit results by sending transaction ID as input.

When I'm passing transaction id directly in the function as below I'm able to get the response successfully

Request:
api_response2 = api_instance.get_audits_query_transaction_id_results(transaction_id='d68b93b7-057d-4acb-a12c-e5c93536a07a')
print(api_response2.entities[0])

Response:

{'action': 'Read',
'client': {'id': '', 'self_uri': None},
'context': {'conversationId': 'fbeb839f-6a72-4c97'},
'entity': {'id': '10d895cd-5a4b-44',
'self_uri': '/api/v2/conversations/fbeb839f-6a72-4c97/recordings/10d895cd-5a4b-441d'},
'entity_type': 'Recording',
'event_date': datetime.datetime(2020, 5, 18, 11, 48, 58, tzinfo=tzutc()),
'id': '0f5c1f8c-2a83-4f89',
'message': None,
'property_changes': [],
'remote_ip': ['34.212.133.158', '64.252.141.160', '10.85.211.40'],
'service_name': 'Quality',
'user': {'id': '56def0eb-5551-4a8c-',
'name': None,
'self_uri': '/api/v2/users/56def0eb-5551-4a8c-'}}

But If I pass the same transaction ID as variable which I got as a response from other API, its throwing error.

Request:
api_response1 = api_instance.post_audits_query(body)
transaction_id = api_response1.id
api_response2 = api_instance.get_audits_query_transaction_id_results(transaction_id=t)
print(api_response2.entities[0])

Response:
Traceback (most recent call last):
File "c:/AuditAPI.py", line 35, in
api_response2 = api_instance.get_audits_query_transaction_id_results(transaction_id=api_response1.id)
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PureCloudPlatformClientV2\apis\audit_api.py", line 202, in get_audits_query_transaction_id_results
response = self.api_client.call_api(resource_path, 'GET',
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 396, in call_api
return self.__call_api(resource_path, method,
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 220, in __call_api
response_data = self.request(method, url,
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PureCloudPlatformClientV2\api_client.py", line 417, in request
return self.rest_client.GET(url,
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PureCloudPlatformClientV2\rest.py", line 205, in GET
return self.request("GET", url,
File "C:\Users\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PureCloudPlatformClientV2\rest.py", line 200, in request
raise ApiException(http_resp=r)
PureCloudPlatformClientV2.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '218', 'Connection': 'keep-alive', 'Date': 'Wed, 03 Jun 2020 06:34:02 GMT', 'ININ-Correlation-Id': '5bc47bb5-bd8e-4b72-a9e9-9e82901937de', 'inin-ratelimit-count': '2', 'inin-ratelimit-allowed': '300', 'inin-ratelimit-reset': '60', 'Strict-Transport-Security': 'max-age=600; includeSubDomains', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 dc57dadfhjkdfl67afa847c0ba.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'BLR50-C2', 'X-Amz-Cf-Id': 'hrkXKihxUEzIkzPkrufodjflksjnlksdjdlAkdjfdksf'})
HTTP response body: {"message":"Query execution not completed for id [15de4436-8808-49c5-aa75-a11c99778f65]","code":"bad.request","status":400,"messageParams":{},"contextId":"5bc47bb5-bd8e-4b72-a9e9-9e82901937de","details":[],"errors":[]}

I don't know what I'm missing here. Can someone please help me out?

The 400 bad request with this message means that the results are not yet available and you are not yet allowed to retrieve them. Use GET /api/v2/audits/query/{transactionId} to check the status of the query on an interval and wait until the state is succeeded before retrieving the results.

1 Like

Thanks Tim. It works!!

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