Skip to content

Conversation

@jawad-khan
Copy link
Contributor

@jawad-khan jawad-khan commented Nov 18, 2025

Pull Request

This PR adds support for the Meilisearch Webhooks API to the Python SDK.
It introduces a new client methods to create, list, fetch, update, and delete webhooks.

The implementation follows the existing SDK structure and uses the same HTTP layer already in place. Basic tests are included to cover webhook creation, listing, fetching, delivery listing, and deletion.

Related issue

Fixes #1132

What does this PR do?

  • This PR adds support for the Meilisearch Webhooks API to the Python SDK.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features

    • Added webhook management: list webhooks, retrieve a webhook, create webhooks with custom headers, update webhook settings, and delete webhooks.
  • Documentation

    • Added new webhook usage examples to the code samples.
  • Tests

    • Added end-to-end tests covering webhook CRUD, error cases, and a cleanup fixture to ensure tests run independently.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 18, 2025

Walkthrough

Adds webhook management to the Meilisearch Python client: new webhook Pydantic models, client CRUD methods and config path, code-samples entries, tests, and an autouse fixture that clears webhooks around each test.

Changes

Cohort / File(s) Summary
Data Models
meilisearch/models/webhook.py
New Pydantic models Webhook and WebhooksResults to represent webhook entities and result lists.
Client API
meilisearch/client.py
Added webhook CRUD methods on Client: get_webhooks(), get_webhook(webhook_uuid), create_webhook(options), update_webhook(webhook_uuid, options), delete_webhook(webhook_uuid). Methods call /webhooks endpoints and return model instances or status.
Configuration
meilisearch/config.py
Added webhooks = "webhooks" to Config.Paths.
Code Samples
.code-samples.meilisearch.yaml
Added example snippets for webhook operations: get_webhooks, get_webhook('WEBHOOK_UID'), create_webhook(...), update_webhook(...), delete_webhook(...).
Tests & Fixtures
tests/client/test_client_webhooks_meilisearch.py, tests/conftest.py
New tests covering CRUD success and error paths for webhooks. Added autouse fixture clear_webhooks(client) to delete all webhooks after each test.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant Client
    participant API as Meilisearch API

    Note over Test,Client: List webhooks
    Test->>Client: get_webhooks()
    Client->>API: GET /webhooks
    API-->>Client: WebhooksResults
    Client-->>Test: WebhooksResults

    Note over Test,Client: Create webhook
    Test->>Client: create_webhook({url, headers})
    Client->>API: POST /webhooks
    API-->>Client: Webhook (uuid)
    Client-->>Test: Webhook

    Note over Test,Client: Read / Update / Delete
    Test->>Client: get_webhook(uuid)
    Client->>API: GET /webhooks/{uuid}
    API-->>Client: Webhook
    Client-->>Test: Webhook

    Test->>Client: update_webhook(uuid, {url})
    Client->>API: PATCH /webhooks/{uuid}
    API-->>Client: Webhook
    Client-->>Test: Webhook

    Test->>Client: delete_webhook(uuid)
    Client->>API: DELETE /webhooks/{uuid}
    API-->>Client: 204
    Client-->>Test: 204 / status
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to serialization/deserialization between API responses and the Pydantic models (camelCase mapping, optional headers).
  • Verify correct path usage in client.py against Config.Paths.webhooks.
  • Review test fixture clear_webhooks for race conditions or unintended interactions with parallel tests.

Poem

🐇 I hopped through code with nimble feet,
New webhooks born, a tidy feat.
Create and fetch, then update, delete —
Models snug and tests complete.
A rabbit cheered: "Nice work, neat!"

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Add support for webhooks api' directly and clearly summarizes the main change—adding webhook API support to the Meilisearch Python SDK.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
meilisearch/client.py (1)

510-532: Clarify required fields in docstring.

The docstring says options "Can include" url and headers but doesn't specify what's required. Based on the test coverage (test_create_webhook_missing_required_fields), the url field appears to be required. Consider updating the docstring to be more explicit, similar to how create_key (lines 392-417) clearly states mandatory fields.

Example improvement:

         options:
-            The webhook configuration. Can include:
-            - url: The URL to send the webhook to
-            - headers: Dictionary of HTTP headers to include in webhook requests
+            The webhook configuration:
+            - url (required): The URL to send the webhook to
+            - headers (optional): Dictionary of HTTP headers to include in webhook requests
meilisearch/models/webhook.py (1)

7-16: Consider adding field validation.

The model correctly uses CamelBase for automatic case conversion and defines all necessary fields. As an optional enhancement, you could add Pydantic validators for the url field (e.g., HttpUrl type) and uuid field (e.g., UUID format validation) to catch invalid data early.

Example (optional):

from pydantic import HttpUrl, field_validator
from uuid import UUID

class Webhook(CamelBase):
    """Model for a Meilisearch webhook."""

    model_config = ConfigDict(arbitrary_types_allowed=True)

    uuid: str  # Could be UUID type
    url: str  # Could be HttpUrl type
    headers: Optional[Dict[str, Any]] = None
    isEditable: bool
    
    @field_validator('uuid')
    def validate_uuid(cls, v):
        # Validate UUID format if desired
        return v
tests/client/test_client_webhooks_meilisearch.py (1)

16-31: Consider verifying all headers in the assertion.

The test creates a webhook with two headers (Authorization and X-Custom-Header) but only verifies X-Custom-Header in the assertion (line 30). Consider verifying both headers or the complete headers dict to ensure the API correctly stores all provided headers.

Optional enhancement:

     assert webhook.uuid is not None
     assert webhook.url == webhook_data["url"]
-    assert webhook.headers["X-Custom-Header"] == webhook_data["headers"]["X-Custom-Header"]
+    assert webhook.headers == webhook_data["headers"]
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87cf84b and e3ea9c3.

📒 Files selected for processing (6)
  • .code-samples.meilisearch.yaml (1 hunks)
  • meilisearch/client.py (2 hunks)
  • meilisearch/config.py (1 hunks)
  • meilisearch/models/webhook.py (1 hunks)
  • tests/client/test_client_webhooks_meilisearch.py (1 hunks)
  • tests/conftest.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/client/test_client_webhooks_meilisearch.py (3)
meilisearch/errors.py (1)
  • MeilisearchApiError (28-51)
tests/conftest.py (1)
  • client (15-16)
meilisearch/client.py (5)
  • get_webhooks (471-486)
  • create_webhook (510-532)
  • get_webhook (488-508)
  • update_webhook (534-558)
  • delete_webhook (560-580)
meilisearch/client.py (3)
meilisearch/models/webhook.py (2)
  • Webhook (7-15)
  • WebhooksResults (18-22)
meilisearch/_httprequests.py (4)
  • get (95-96)
  • post (98-108)
  • patch (110-118)
  • delete (142-147)
meilisearch/index.py (1)
  • delete (88-105)
tests/conftest.py (1)
meilisearch/client.py (2)
  • get_webhooks (471-486)
  • delete_webhook (560-580)
🔇 Additional comments (16)
.code-samples.meilisearch.yaml (1)

770-785: LGTM!

The webhook code samples follow the existing patterns in this file and provide clear examples for all CRUD operations.

meilisearch/config.py (1)

50-50: LGTM!

The webhook path constant follows the established pattern for other API paths.

meilisearch/client.py (5)

35-35: LGTM!

The import statement follows the established pattern for other model imports in this file.


471-486: LGTM!

The get_webhooks implementation follows the established pattern from get_keys (lines 367-390). Consider adding optional pagination parameters in the future if the webhook API supports them, similar to how get_keys accepts parameters.


488-508: LGTM!

The get_webhook method follows the established pattern from get_key (lines 344-365) and correctly handles webhook retrieval by UUID.


534-558: LGTM!

The update_webhook method follows the established pattern from update_key (lines 419-444) and correctly handles partial updates.


560-580: LGTM!

The delete_webhook method follows the established pattern from delete_key (lines 446-467) and correctly returns the status code.

meilisearch/models/webhook.py (2)

1-4: LGTM!

The imports are appropriate for Pydantic models that need camelCase conversion.


18-22: LGTM!

The WebhooksResults model is simple and appropriate for wrapping the webhook list response. Note that unlike some other result models in the SDK, this doesn't include pagination fields (offset, limit, total). This should match the actual API response structure.

tests/client/test_client_webhooks_meilisearch.py (7)

8-13: LGTM!

This test correctly verifies the empty state when no webhooks exist.


33-47: LGTM!

This test correctly verifies webhook retrieval by creating a webhook and then fetching it back.


49-52: LGTM!

This negative test correctly verifies that fetching a non-existent webhook raises the appropriate error.


55-73: LGTM!

This test correctly verifies webhook updates, ensuring the UUID persists while the URL is updated.


75-92: LGTM!

This test provides comprehensive coverage of webhook deletion, verifying both the status code and confirming the webhook is actually deleted by attempting to retrieve it.


94-97: LGTM!

This negative test correctly verifies that deleting a non-existent webhook raises the appropriate error.


100-110: LGTM!

This validation test correctly verifies that the API enforces required fields when creating a webhook.

@curquiza curquiza changed the title feat: Added webhooks apis issue#1132 Add support for webhooks api Nov 21, 2025
@curquiza curquiza added the enhancement New feature or request label Nov 21, 2025
Copy link
Contributor

@Strift Strift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jawad-khan and thanks for this contribution 🙌

@Strift Strift added this pull request to the merge queue Nov 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 24, 2025
@Strift Strift added this pull request to the merge queue Nov 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 24, 2025
@Strift Strift added this pull request to the merge queue Nov 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 24, 2025
@Strift Strift added this pull request to the merge queue Nov 24, 2025
Merged via the queue into meilisearch:main with commit cde48b9 Nov 24, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.17.0] Add support for webhook API

3 participants