/// <summary> /// Load a bulk location file into BLIP. /// </summary> /// <param name="brandKey">The unique identifier for a single brand.</param> /// <param name="source">The unique identifier for the data source.</param> /// <param name="filePath">The full path to the bulk location file.</param> /// <param name="implicitDelete">Whether or not to delete locations from BLIP if they're missing from the file.</param> /// <param name="expectedRecordCount">The number of location records to expect in the file.</param> /// <param name="successEmail">An optional email address to notify upon success. Can be a comma-delimited list.</param> /// <param name="failEmail">An optional email address to notify upon failure. Can be a comma-delimited list.</param> /// <param name="successCallbackUrl">An optional URL to call upon success.</param> /// <param name="failCallbackUrl">An optional URL to call upon failure.</param> /// <returns>BlipResponse object with a status code and body text if applicable.</returns> public BlipResponse BulkLoad(string brandKey, string source, string filePath, bool implicitDelete, int expectedRecordCount, string successEmail = null, string failEmail = null, string successCallbackUrl = null, string failCallbackUrl = null) { // Validate optional parameters var optionalParams = ""; if (!string.IsNullOrEmpty(successEmail)) { if (IsValidEmail(successEmail)) { optionalParams += $"&successEmail={successEmail}"; } else { return(new BlipResponse(400, $"Error: successEmail is not valid. {successEmail}")); } } if (!string.IsNullOrEmpty(failEmail)) { if (IsValidEmail(failEmail)) { optionalParams += $"&failEmail={failEmail}"; } else { return(new BlipResponse(400, $"Error: failEmail is not valid. {failEmail}")); } } if (!string.IsNullOrEmpty(successCallbackUrl)) { if (IsValidUrl(successCallbackUrl)) { optionalParams += $"&successCallback={successCallbackUrl}"; } else { return(new BlipResponse(400, $"Error: successCallbackUrl is not valid. {successCallbackUrl}")); } } if (!string.IsNullOrEmpty(failCallbackUrl)) { if (IsValidUrl(failCallbackUrl)) { optionalParams += $"&failCallback={failCallbackUrl}"; } else { return(new BlipResponse(400, $"Error: failCallbackUrl is not valid. {failCallbackUrl}")); } } // Use pre-seigned auth from BLIP to upload the file to S3 var blipRequest = new BlipRequest(Credentials, Endpoint); var s3UploadResponse = S3Request.Upload(blipRequest, brandKey, filePath); // Return error response if S3 upload fails if (s3UploadResponse.StatusCode != 204) { return(s3UploadResponse); } // Build query string var path = $"/brand/{brandKey}/bulkLoad?"; var s3Path = s3UploadResponse.Body; var delete = implicitDelete.ToString().ToLower(); var count = expectedRecordCount.ToString(); path += $"s3Path={s3Path}&source={source}&implicitDelete={delete}&expectedRecordCount={count}"; if (!string.IsNullOrEmpty(optionalParams)) { path += optionalParams; } // Ask BLIP to load the file from S3 and return its response (success of failure) return(blipRequest.ExecuteCommand(BlipRequest.Command.Get, path).Result); }