Issues formatting request for RecordingApi post_recording_batchrequests

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 "batch_download_request_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: )

Hi,

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

Regards,
Declan


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).

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

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

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