Skip to content

Latest commit

 

History

History
244 lines (165 loc) · 37.2 KB

README.md

File metadata and controls

244 lines (165 loc) · 37.2 KB

Webhooks

Overview

Available Operations

list

List the webhooks of the project. The list is paginated.

Example Usage

from moderation_api import ModerationAPI
import os


with ModerationAPI(
    secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:

    res = ma_client.webhooks.list(page=1, page_size=20)

    while res is not None:
        # Handle items

        res = res.next()

Parameters

Parameter Type Required Description
page Optional[int] ➖ N/A
page_size Optional[int] ➖ N/A
project_id Optional[str] ➖ The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.ListWebhooksResponse

Errors

Error Type Status Code Content Type
errors.AuthenticationError 401 application/json
errors.RateLimitError 429 application/json
errors.ModerationAPIDefaultError 4XX, 5XX */*

create

Create a webhook subscribed to one or more event types. Deliveries use the v2 envelope and are signed with the project signing secret (see the signing secret endpoint).

Example Usage

from moderation_api import ModerationAPI
import os


with ModerationAPI(
    secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:

    res = ma_client.webhooks.create(name="Moderation events", url="https://example.com/webhooks/moderation", event_types=[
        "QUEUE_ITEM_REJECTED",
        "AUTHOR_BLOCKED",
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
name str ✔️ The webhook's name, used to identify it in the dashboard
url str ✔️ The webhook's URL. We'll call this URL when an event occurs.
event_types List[models.CreateWebhookEventTypeRequest] ✔️ Event types this webhook subscribes to. One webhook URL receives all events you list here.
project_id Optional[str] ➖ The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error.
description OptionalNullable[str] ➖ The webhook's description
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.CreateWebhookResponse

Errors

Error Type Status Code Content Type
errors.BadRequestError 400 application/json
errors.AuthenticationError 401 application/json
errors.RateLimitError 429 application/json
errors.ModerationAPIDefaultError 4XX, 5XX */*

retrieve

Get a webhook by ID.

Example Usage

from moderation_api import ModerationAPI
import os


with ModerationAPI(
    secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:

    res = ma_client.webhooks.retrieve(id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
id str ✔️ The ID of the webhook to get.
project_id Optional[str] ➖ The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.GetWebhookResponse

Errors

Error Type Status Code Content Type
errors.AuthenticationError 401 application/json
errors.NotFoundError 404 application/json
errors.RateLimitError 429 application/json
errors.ModerationAPIDefaultError 4XX, 5XX */*

update

Update a webhook. Legacy v1 webhooks are read-only: delete them and create a new webhook instead.

Example Usage

from moderation_api import ModerationAPI
import os


with ModerationAPI(
    secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:

    res = ma_client.webhooks.update(id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
id str ✔️ The ID of the webhook to update.
project_id Optional[str] ➖ The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error.
name Optional[str] ➖ The webhook's name, used to identify it in the dashboard
description OptionalNullable[str] ➖ The webhook's description
url Optional[str] ➖ The webhook's URL. We'll call this URL when an event occurs.
event_types List[models.UpdateWebhookEventTypeRequest] ➖ Event types this webhook subscribes to. One webhook URL receives all events you list here.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.UpdateWebhookResponse

Errors

Error Type Status Code Content Type
errors.BadRequestError 400 application/json
errors.AuthenticationError 401 application/json
errors.NotFoundError 404 application/json
errors.RateLimitError 429 application/json
errors.ModerationAPIDefaultError 4XX, 5XX */*

delete

Delete a webhook.

Example Usage

from moderation_api import ModerationAPI
import os


with ModerationAPI(
    secret_key=os.getenv("MODAPI_SECRET_KEY", ""),
) as ma_client:

    res = ma_client.webhooks.delete(id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
id str ✔️ The ID of the webhook to delete.
project_id Optional[str] ➖ The project to act on, by ID or name. Required with an organization key unless the key reaches only one project; list projects with GET /projects. A project key acts on its own project and needs no value: naming another one is an error.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.DeleteWebhookResponse

Errors

Error Type Status Code Content Type
errors.AuthenticationError 401 application/json
errors.NotFoundError 404 application/json
errors.RateLimitError 429 application/json
errors.ModerationAPIDefaultError 4XX, 5XX */*