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