update_document_fields
Modify text fields in multiple SignNow documents by specifying document IDs and field values to update.
Instructions
Update text fields in multiple documents (only individual documents, not document groups)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| update_requests | Yes | Array of document field update requests |
Implementation Reference
- Core handler function _update_document_fields that loops through update requests and calls the SignNow API client.prefill_text_fields for each document.def _update_document_fields(client: SignNowAPIClient, token: str, update_requests: list[UpdateDocumentFields]) -> UpdateDocumentFieldsResponse: """ Update fields for multiple documents. This function updates text fields in multiple documents using the SignNow API. Only text fields can be updated using the prefill_text_fields endpoint. Args: client: SignNow API client instance token: Access token for authentication update_requests: List of UpdateDocumentFields with document IDs and fields to update Returns: UpdateDocumentFieldsResponse with results for each document update """ results = [] for update_request in update_requests: try: # Convert FieldToUpdate to PrefillTextField format prefill_fields = [] for field in update_request.fields: prefill_fields.append({"field_name": field.name, "prefilled_text": field.value}) # Create PrefillTextFieldsRequest from signnow_client.models.templates_and_documents import ( PrefillTextField, PrefillTextFieldsRequest, ) prefill_request = PrefillTextFieldsRequest(fields=[PrefillTextField(field_name=field.name, prefilled_text=field.value) for field in update_request.fields]) # Update fields using the client success = client.prefill_text_fields(token=token, document_id=update_request.document_id, request_data=prefill_request) results.append(UpdateDocumentFieldsResult(document_id=update_request.document_id, updated=success, reason=None)) # No reason needed for success except Exception as e: # Log error and mark as failed error_message = str(e) print(f"Failed to update fields for document {update_request.document_id}: {error_message}") results.append(UpdateDocumentFieldsResult(document_id=update_request.document_id, updated=False, reason=error_message)) return UpdateDocumentFieldsResponse(results=results)
- src/sn_mcp_server/tools/signnow.py:738-786 (registration)MCP tool registration and thin handler wrapper that authenticates and delegates to the core _update_document_fields implementation.@mcp.tool( name="update_document_fields", description="Update text fields in multiple documents (only individual documents, not document groups)", tags=["document", "fields", "update", "prefill"], ) def update_document_fields( ctx: Context, update_requests: Annotated[ list[UpdateDocumentFields], Field( description="Array of document field update requests", examples=[ [ { "document_id": "abc123", "fields": [ {"name": "FieldName1", "value": "New Value 1"}, {"name": "FieldName2", "value": "New Value 2"}, ], }, { "document_id": "def456", "fields": [{"name": "FieldName3", "value": "New Value 3"}], }, ], ], ), ], ) -> UpdateDocumentFieldsResponse: """Update text fields in multiple documents. This tool updates text fields in multiple documents using the SignNow API. Only text fields can be updated using the prefill_text_fields endpoint. IMPORTANT: This tool works only with individual documents, not document groups. To find out what fields are available in a document or document group, use the get_document tool first. Args: update_requests: Array of UpdateDocumentFields with document IDs and fields to update Returns: UpdateDocumentFieldsResponse with results for each document update """ token, client = _get_token_and_client(token_provider) # Initialize client and use the imported function from document module return _update_document_fields(client, token, update_requests)
- Pydantic schema definitions for input (UpdateDocumentFields containing list of FieldToUpdate) and output (UpdateDocumentFieldsResponse with list of results).class FieldToUpdate(BaseModel): """Single field to update in a document.""" name: str = Field(..., description="Name of the field to update") value: str = Field(..., description="New value for the field") class UpdateDocumentFields(BaseModel): """Request model for updating document fields.""" document_id: str = Field(..., description="ID of the document to update") fields: list[FieldToUpdate] = Field(..., description="Array of fields to update with their new values") class UpdateDocumentFieldsResult(BaseModel): """Result of updating document fields.""" document_id: str = Field(..., description="ID of the document that was updated") updated: bool = Field(..., description="Whether the document fields were successfully updated") reason: str | None = Field(None, description="Reason for failure if updated is false") class UpdateDocumentFieldsResponse(BaseModel): """Response model for updating document fields.""" results: list[UpdateDocumentFieldsResult] = Field(..., description="Array of update results for each document")