This sample demonstrates how to call the /aws/api/pdf/redact endpoint using a MultipartFormDataContent request with the required Bearer Token and Regex configuration.
public async Task RedactPdfWithRegexAsync(string inputFilePath, string outputFilePath) { using var client = new HttpClient(); // Set Authentication Header client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "YOUR_API_KEY"); using var form = new MultipartFormDataContent(); // Redaction configuration with EMAIL, SSN, and custom Regex var redactionConfigJson = @"{ ""types"": [""EMAIL_ADDRESS"", ""SSN""], ""regex"": [""\\b\\d{3}-\\d{2}-\\d{4}\\b""] }"; form.Add(new StringContent(redactionConfigJson), "redaction_config"); // Prepare file: must use "file:fileName" format as per Swagger byte[] fileBytes = await File.ReadAllBytesAsync(inputFilePath); var fileContent = new ByteArrayContent(fileBytes); fileContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/pdf"); string fileName = Path.GetFileName(inputFilePath); form.Add(fileContent, "file", $"file:{fileName}"); // Execute Synchronous POST var response = await client.PostAsync("https://services.forecastica.com/aws/api/pdf/redact", form); if (response.IsSuccessStatusCode) { byte[] redactedPdf = await response.Content.ReadAsByteArrayAsync(); await File.WriteAllBytesAsync(outputFilePath, redactedPdf); } }