/// <summary> /// Request a job to download recordings assosciated with the specified conversations /// </summary> /// <param name="conversationIDs"></param> /// <param name="api"></param> /// <returns></returns> private static string RequestBatchDownload(List <string> conversationIDs, RecordingApi api) { // Convert List of Strings to List of BatchDownloadRequests List <BatchDownloadRequest> batchRequest = new List <BatchDownloadRequest>(); foreach (string id in conversationIDs) { BatchDownloadRequest batchDownloadRequest = new BatchDownloadRequest(ConversationId: id); batchRequest.Add(batchDownloadRequest); } // Create the batch job with the request list BatchDownloadJobSubmission batchSubmission = new BatchDownloadJobSubmission(BatchDownloadRequestList: batchRequest); return(api.PostRecordingBatchrequests(batchSubmission).Id); }
/// <summary> /// Plot conversationId and recordingId to request for batchDownload Recordings /// </summary> /// <param name="iterateRecordings"></param> /// <returns></returns> private static void getSpecificRecordings(Recording iterateRecordings) { List <BatchDownloadRequest> batchRequest = new List <BatchDownloadRequest>(); BatchDownloadRequest batchDownloadRequest = new BatchDownloadRequest(ConversationId: iterateRecordings.ConversationId, RecordingId: iterateRecordings.Id); batchRequest.Add(batchDownloadRequest); // Create the batch job with the request list BatchDownloadJobSubmission batchSubmission = new BatchDownloadJobSubmission(BatchDownloadRequestList: batchRequest); BatchDownloadJobSubmissionResult recordingBatchRequestId = new BatchDownloadJobSubmissionResult(); RecordingApi recordingApi = new RecordingApi(); recordingBatchRequestId = recordingApi.PostRecordingBatchrequests(batchSubmission); recordingStatus(recordingBatchRequestId); }
/// <summary> /// Batch download recordings. /// Link: https://developer.mypurecloud.com/api/rest/v2/recording/#post-api-v2-recording-batchrequests /// </summary> /// <param name="conversationId">String, conversation id</param> /// <returns>BatchDownloadJobSubmissionResult, Job result object</returns> public async Task <BatchDownloadJobSubmissionResult> BatchRecordingDownloadByConversation(List <string> conversations) { BatchDownloadJobSubmissionResult result = new BatchDownloadJobSubmissionResult(); using (HttpClient hc = new HttpClient()) { hc.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"Bearer {_token}"); hc.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); HttpResponseMessage responseMessage = new HttpResponseMessage(); BatchDownloadJobSubmission queryParam = new BatchDownloadJobSubmission { BatchDownloadRequestList = conversations .Select(c => new BatchDownloadRequest() { ConversationId = c }).ToList() }; int tentatives = 0; do { responseMessage = await hc.PostAsync(_uribase + "/api/v2/recording/batchrequests", new StringContent(queryParam.ToJson(), Encoding.UTF8, "application/json")); string jsonMessage = await responseMessage.Content.ReadAsStringAsync(); if (responseMessage.IsSuccessStatusCode) { result = JsonConvert.DeserializeObject <BatchDownloadJobSubmissionResult>(jsonMessage); } else if (responseMessage.StatusCode == HttpStatusCode.TooManyRequests) { await DelayTime(responseMessage); } else if ((int)responseMessage.StatusCode >= 300 && (int)responseMessage.StatusCode < 600) { throw new Exception(jsonMessage); } tentatives++; } while (!responseMessage.IsSuccessStatusCode && tentatives < 3); } return(result); }