Legacy Dev Forum Posts

 View Only

Sign Up

PureCloudPlatformClientV2 not functioning as expected

  • 1.  PureCloudPlatformClientV2 not functioning as expected

    Posted 06-05-2025 18:08

    Marty_Hand | 2020-08-05 21:23:21 UTC | #1

    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 <module> 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


    tim.smith | 2020-08-06 16:42:12 UTC | #2

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

    Marty_Hand, post:1, topic:8492
    Anaconda and PyCharm

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


    Marty_Hand | 2020-08-06 17:02:23 UTC | #3

    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

    clientid = 'clientid' clientsecret = 'clientsecret'

    Authenticate client

    apiclient = PureCloudPlatformClientV2.apiclient.ApiClient().getclientcredentialstoken(clientid, client_secret)

    Get the api

    recordingapi = PureCloudPlatformClientV2.RecordingApi(apiclient)

    accesstoken = recordingapi.apiclient.accesstoken

    Assign the token

    PureCloudPlatformClientV2.configuration.accesstoken = accesstoken

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

    query = PureCloudPlatformClientV2.RecordingJobsQuery() query.action = "DELETE" query.actiondate = "2020-08-06T00:20:00.000Z" query.integrationid = "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 createrecordingjob api

    createjobresponse = recordingapi.postrecordingjobs(query) jobid = createjobresponse.id print(f"Succesfully created recording bulk job { createjobresponse}") print(jobid) except ApiException as e: print(f"Exception when calling RecordingApi->postrecording_jobs: { e }") sys.exit()

    Call getrecordingjob api

    while True: try: getrecordingjobresponse = recordingapi.getrecordingjob(jobid) jobstate = getrecordingjobresponse.state if jobstate != 'PENDING': break else: time.sleep(2) except ApiException as e: print(f"Exception when calling RecordingApi->getrecordingjob: { e }") sys.exit()

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

    Call deleterecordingjob api

    Can be canceled also in READY and PENDING states

    if jobstate == 'PROCESSING': try: canceljobresponse = recordingapi.deleterecordingjob(jobid) print(f"Succesfully cancel recording bulk job { executejobresponse}") except ApiException as e: print(f"Exception when calling RecordingApi->deleterecording_job: { e }") sys.exit()

    try: getrecordingjobsresponse = recordingapi.getrecordingjobs({ "pagesize": 25, "pagenumber": 1, "sortby": "userId", # or "dateCreated" "state": "READY", # valid values FULFILLED, PENDING, READY, PROCESSING, CANCELLED, FAILED "showonlymyjobs": True, "jobtype": "EXPORT", # or "DELETE" }) print(f"Succesfully get recording bulk jobs { executejobresponse}") except ApiException as e: print(f"Exception when calling RecordingApi->getrecording_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', 'actiondate': '2020-08-06T00:20:00.000Z', 'conversationquery': {'interval': '2020-07-28T00:00:00.000Z/2020-07-29T23:59:59.000Z', 'order': 'asc', 'orderBy': 'conversationStart'}, 'includescreenrecordings': None, 'integrationid': 'integration-id'} End Exception when calling RecordingApi->postrecording_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


    tim.smith | 2020-08-06 17:16:04 UTC | #4

    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"

    Marty_Hand | 2020-08-10 22:41:18 UTC | #5

    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.


    Marty_Hand | 2020-08-11 17:47:01 UTC | #6

    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.


    tim.smith | 2020-08-18 14:40:00 UTC | #7

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


    system | 2020-09-18 14:40:02 UTC | #8

    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: 8492