fix: use field ID for Paperless custom field updates

Paperless API requires field ID (integer) not field name (string)
when updating custom fields. Now looks up field ID by name before
updating library_indexed custom field.

Also includes webhook debugging endpoint for development.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-25 16:37:26 +01:00
co-authored by Claude Opus 4.5
parent f2b8c7d111
commit 867de65354
4 changed files with 159 additions and 27 deletions
+18 -13
View File
@@ -86,22 +86,27 @@ class DocumentUploadResponse(BaseModel):
class PaperlessWebhookPayload(BaseModel):
"""Payload from Paperless-ngx webhook (include_document=true format)."""
id: int = Field(..., description="Paperless document ID")
"""
Payload from Paperless-ngx webhook.
Supports Jinja template format:
- doc_url: Contains document ID in URL path (e.g., http://paperless:8000/documents/123/)
- title: Document title from {{ doc_title }}
"""
doc_url: str = Field(..., description="Paperless document URL containing ID")
title: Optional[str] = Field(None, description="Document title")
content: Optional[str] = Field(None, description="Document text content")
correspondent: Optional[int] = Field(None, description="Correspondent ID")
document_type: Optional[int] = Field(None, description="Document type ID")
tags: List[int] = Field(default_factory=list, description="Tag IDs")
created: Optional[str] = Field(None, description="Created date")
modified: Optional[str] = Field(None, description="Modified datetime")
added: Optional[str] = Field(None, description="Added datetime")
original_file_name: Optional[str] = Field(None, description="Original filename")
owner: Optional[int] = Field(None, description="Owner user ID")
custom_fields: List[Dict[str, Any]] = Field(default_factory=list, description="Custom fields")
class Config:
extra = "ignore" # Ignore extra fields from Paperless
extra = "ignore" # Ignore extra fields
@property
def document_id(self) -> int:
"""Extract document ID from doc_url."""
import re
match = re.search(r'/documents/(\d+)/?', self.doc_url)
if match:
return int(match.group(1))
raise ValueError(f"Cannot extract document ID from URL: {self.doc_url}")
class WebhookResponse(BaseModel):