PureCloudPlatformClientV2 not functioning as expected

Good day, I am trying to use the PureCloudPlatformClientV2 package with Python to delete call recordings en mass. The tutorial here (https://developer.mypurecloud.com/api/tutorials/recordings-bulk-actions/index.html?language=python&step=1) has what should be working code. However, when I use this sample and replace the client ID and secret with mine, I get errors. All of them basically say that any of the attributes of PureCloudPlatformClientV2 that are being called don't exist. I get this as the first error:

Traceback (most recent call last):
File "C:/Users/mhand/PycharmProjects/pythonProject/delete recordings.py", line 4, in
from PureCloudPlatformClientV2.rest import ApiException
ModuleNotFoundError: No module named 'PureCloudPlatformClientV2.rest'

Process finished with exit code 1

Anyone have thoughts on why the package calls don't appear to be able to retrieve the API calls? I have verified that I am using the latest package version and I am running on Python 3.8 using Anaconda and PyCharm

It sounds like maybe you don't have the package installed correctly.

I'm not familiar with those. Can you run the script using plain python to see if the issue is caused by those things?

Thanks, Tim. I moved to a different Python platform (Jupyter) and have the code there, but am now getting a different error. The following is my code:

import base64, sys, requests, time
import PureCloudPlatformClientV2
from pprint import pprint
from PureCloudPlatformClientV2.rest import ApiException

print('-------------------------------------------------------------')
print('- Execute Bulk Action on recordings-')
print('-------------------------------------------------------------')

OAuth when using Client Credentials

client_id = 'client_id'
client_secret = 'client_secret'

Authenticate client

api_client = PureCloudPlatformClientV2.api_client.ApiClient().get_client_credentials_token(client_id, client_secret)

Get the api

recording_api = PureCloudPlatformClientV2.RecordingApi(api_client)

access_token = recording_api.api_client.access_token

Assign the token

PureCloudPlatformClientV2.configuration.access_token = access_token

Build the create job query, for export action, set query.action = "EXPORT"

query = PureCloudPlatformClientV2.RecordingJobsQuery()
query.action = "DELETE"
query.action_date = "2020-08-06T00:20:00.000Z"
query.integration_id = "integration-id"
query.conversation_query = {
"interval": "2020-07-28T00:00:00.000Z/2020-07-29T23:59:59.000Z",
"order": "asc",
"orderBy": "conversationStart"
}
print(f"start")
print(query)
print(f"End")
try:
# Call create_recording_job api
create_job_response = recording_api.post_recording_jobs(query)
job_id = create_job_response.id
print(f"Succesfully created recording bulk job { create_job_response}")
print(job_id)
except ApiException as e:
print(f"Exception when calling RecordingApi->post_recording_jobs: { e }")
sys.exit()

Call get_recording_job api

while True:
try:
get_recording_job_response = recording_api.get_recording_job(job_id)
job_state = get_recording_job_response.state
if job_state != 'PENDING':
break
else:
time.sleep(2)
except ApiException as e:
print(f"Exception when calling RecordingApi->get_recording_job: { e }")
sys.exit()

if job_state == 'READY':
try:
execute_job_response = recording_api.put_recording_job(job_id, { "state": "PROCESSING"})
print(f"Succesfully execute recording bulk job { execute_job_response}")
except ApiException as e:
print(f"Exception when calling RecordingApi->put_recording_job: { e }")
sys.exit()
else:
print(f"Expected Job State is: READY, however actual Job State is: { job_state }")

Call delete_recording_job api

Can be canceled also in READY and PENDING states

if job_state == 'PROCESSING':
try:
cancel_job_response = recording_api.delete_recording_job(job_id)
print(f"Succesfully cancel recording bulk job { execute_job_response}")
except ApiException as e:
print(f"Exception when calling RecordingApi->delete_recording_job: { e }")
sys.exit()

try:
get_recording_jobs_response = recording_api.get_recording_jobs({
"page_size": 25,
"page_number": 1,
"sort_by": "userId", # or "dateCreated"
"state": "READY", # valid values FULFILLED, PENDING, READY, PROCESSING, CANCELLED, FAILED
"show_only_my_jobs": True,
"job_type": "EXPORT", # or "DELETE"
})
print(f"Succesfully get recording bulk jobs { execute_job_response}")
except ApiException as e:
print(f"Exception when calling RecordingApi->get_recording_jobs: { e }")
sys.exit()

Obviously I put in my actual client id and secret in my version. However, now I get this error:

{'action': 'DELETE',
'action_date': '2020-08-06T00:20:00.000Z',
'conversation_query': {'interval': '2020-07-28T00:00:00.000Z/2020-07-29T23:59:59.000Z',
'order': 'asc',
'orderBy': 'conversationStart'},
'include_screen_recordings': None,
'integration_id': 'integration-id'}
End
Exception when calling RecordingApi->post_recording_jobs: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '187', 'Connection': 'keep-alive', 'Date': 'Thu, 06 Aug 2020 16:59:19 GMT', 'inin-ratelimit-count': '1', 'inin-ratelimit-allowed': '300', 'inin-ratelimit-reset': '61', 'ININ-Correlation-Id': '41139955-35f8-43fc-af1f-078b56b95c2c', '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 c84ecfd128e1f4c41a53a2b42410f3b8.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'IAD89-C3', 'X-Amz-Cf-Id': 'G2e5YxJ4S3woazEmWFU8ORketemCBjUEDexC9dPQYMpJMmxjVwRdXg=='})
HTTP response body: {"message":"For Delete action don't insert integrationId","code":"bad.request","status":400,"messageParams":{},"contextId":"41139955-35f8-43fc-af1f-078b56b95c2c","details":[],"errors":[]}

Anyone able to help me fix this code?
Thanks
Marty

Please use code markers (``` on the line before and after the code) to format your code in the future. That's really hard to read when it's parsed and formatted as text.

The error states:

For Delete action don't insert integrationId

Don't specify the integration ID in your code, meaning this:

query.integration_id = "integration-id"

Thanks for all of the help. I was able to get this functioning. There is a bug in one of the Python builds (3.8) that does not load PureCloudPlatformClientV2 correctly. Loaded a 3.7.6 notebook on Jupyter and script ran without error.

New question on this topic - Is there a way to limit the action to just voice recordings? The code here deletes all interaction recordings and transcripts.

I believe you can use the query in the request to provide the criteria for the operation.

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