Legacy Dev Forum Posts

 View Only

Sign Up

Issues formatting request for RecordingApi post_recording_batchrequests

  • 1.  Issues formatting request for RecordingApi post_recording_batchrequests

    Posted 06-05-2025 18:09

    Mason_Porter | 2023-11-21 18:21:36 UTC | #1

    I was getting an error when trying to submit a batch download request for recordings using the PythonSDK. Following the documentation here, I wrote this code:

    # Format batch request body
            try:
                body = PureCloudPlatformClientV2.BatchDownloadJobSubmission()
                body.batch_download_request_list = batch_request
                print(f'SUCCESSFULLY FORMATTED BATCH REQUEST {i+1} OF {len(batch_request_body)}')
                print(f'body: {body}')
    
            except Exception as e:
                print(f'Exception when formatting batch request body: {e}')
                raise e
    
           print(f'Posting batch request {i+1} of {len(batch_request_body)}...')
    
            try:
                result = recording_api.post_recording_batchrequests(body)
                print(f'SUCCESSFULLY POSTED BATCH REQUEST {i+1} OF {len(batch_request_body)}')
            except ApiException as e:
                print(f'Exception when calling RecordingApi->post_recording_batchrequests: {e}')
                raise e

    When running this code, I would receive a 400 error with the following message:

    Request list is empty after validation

    When I looked at the printout of the "body", I saw the structure was as follows:

    {'batch_download_request_list': [
        {
             'conversation_id': '***********',
             'recording_id': '************'
        }
      ]
    }

    However, when I look at the REST API documentation, I noticed the request should be formatted in camelCase, like this:

    {'batchDownloadRequestList': [
        {
            'conversationId': '***********',
            'recordingId': '************'
        }
      ]
    }

    When I manually send the body in with that format, I successfully create the batch request. I'm not sure if I'm doing something wrong with the invocation of the "batchdownloadrequest_list" method to format the body or if this is a bug with the SDK, but I thought I'd post in case anyone else is struggling with the same thing.

    TL;DR, try formatting the body after the example in the REST API Documentation (link above) instead of relying on the SDK to format it properly (unless I am misunderstanding how to use the SDK :slight_smile: )


    Declan_ginty | 2023-11-21 19:33:58 UTC | #2

    Hi,

    Would you be able to show what the batch_request variable is equal to?

    Regards, Declan


    Mason_Porter | 2023-11-21 21:17:00 UTC | #4

    Mason_Porter

    1m

    Yes, of course! The batch_request variable is a list of objects with key/value pairs for "conversationId" and "recordingId". For example:

    [{'conversation_id': '*************', 'recording_id': '*************'}, {'conversation_id': '*************', 'recording_id': '*************'}]

    The list is limited to 100 items (if there are more than 100 recordings to pull, I batch them into groups of 100).


    Declan_ginty | 2023-11-21 22:30:32 UTC | #5

    Hi Mason,

    If you look at the documentation for the method you will see that batch_download_request_list is an array of BatchDownloadRequest objects. Instead of a list of custom objects you will need to create an BatchDownloadRequest list similar to this:

        request1 = PureCloudPlatformClientV2.BatchDownloadRequest()
        request1.conversation_id = '***'
        request1.recording_id = "***"
    
        request2 = PureCloudPlatformClientV2.BatchDownloadRequest()
        request2.conversation_id = '***'
        request2.recording_id = "***"
        
        requests = [request1, request2]
    
        body = PureCloudPlatformClientV2.BatchDownloadJobSubmission()
        body.batch_download_request_list = requests

    Hope this helps.

    Regards, Declan


    Mason_Porter | 2023-11-21 22:40:37 UTC | #6

    Declan_ginty, post:5, topic:23257
        request1 = PureCloudPlatformClientV2.BatchDownloadRequest()
        request1.conversation_id = '***'
        request1.recording_id = "***"
    
        request2 = PureCloudPlatformClientV2.BatchDownloadRequest()
        request2.conversation_id = '***'
        request2.recording_id = "***"
        
        requests = [request1, request2]
    
        body = PureCloudPlatformClientV2.BatchDownloadJobSubmission()
        body.batch_download_request_list = requests

    Thanks Declan, this method works perfectly! I must have misunderstood the SDK documentation, but your example was very clear. I appreciate your help!

    For the record, my implementation was like this:

                requests = []
                for r in batch_request:
                    req_obj = PureCloudPlatformClientV2.BatchDownloadRequest()
                    req_obj.conversation_id = r['conversationId']
                    req_obj.recording_id = r['recordingId']
                    requests.append(req_obj)
    
                body = PureCloudPlatformClientV2.BatchDownloadJobSubmission()
                body.batch_download_request_list = requests

    system | 2023-12-22 22:40:49 UTC | #7

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