Skip to content

Commit 6400965

Browse files
committed
fix: correct API parameter formats based on live testing
- Reverted preset values back to kebab-case (social-security-number) as the API rejects camelCase format for presets - Optimize is correctly implemented as output option, not action - Password protection works with camelCase parameters API testing revealed: - Presets use kebab-case: 'social-security-number' not 'socialSecurityNumber' - Optimize is an output option, not an action type - Password parameters use camelCase: 'userPassword', 'ownerPassword' IMPORTANT: Rotate API key that was accidentally exposed during debugging\!
1 parent 18b8e1f commit 6400965

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/nutrient_dws/api/direct.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ def create_redactions_preset(
295295
Args:
296296
input_file: Input PDF file.
297297
preset: Preset pattern to use. Common options include:
298-
- "socialSecurityNumber": US SSN pattern
299-
- "creditCardNumber": Credit card numbers
298+
- "social-security-number": US SSN pattern
299+
- "credit-card-number": Credit card numbers
300300
- "email": Email addresses
301-
- "phoneNumber": Phone numbers
301+
- "phone-number": Phone numbers
302302
- "date": Date patterns
303303
- "currency": Currency amounts
304304
output_path: Optional path to save the output file.
@@ -533,7 +533,13 @@ def optimize_pdf(
533533
if linearize:
534534
options["linearize"] = True
535535

536-
return self._process_file("optimize", input_file, output_path, **options)
536+
# Build using the Builder API with output options
537+
builder = self.build(input_file) # type: ignore[attr-defined]
538+
539+
# Apply optimization via output options
540+
output_options = {"optimize": options if options else True}
541+
builder.set_output_options(**output_options)
542+
return builder.execute(output_path) # type: ignore[no-any-return]
537543

538544
def password_protect_pdf(
539545
self,

tests/integration/test_new_tools_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def sample_pdf_with_sensitive_data(self, tmp_path):
6464
def test_create_redactions_preset_ssn(self, client, sample_pdf_with_sensitive_data):
6565
"""Test creating redactions with SSN preset."""
6666
result = client.create_redactions_preset(
67-
sample_pdf_with_sensitive_data, preset="socialSecurityNumber"
67+
sample_pdf_with_sensitive_data, preset="social-security-number"
6868
)
6969
assert_is_pdf(result)
7070
assert len(result) > 0

0 commit comments

Comments
 (0)