Skip to content

Latest commit

 

History

History
319 lines (225 loc) · 64.6 KB

README.md

File metadata and controls

319 lines (225 loc) · 64.6 KB

Actions

Overview

Available Operations

list

List the moderation actions 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.actions.list(page=1, page_size=20)

    while res is not None:
        # Handle items

        res = res.next()

Parameters

Parameter Type Required Description
queue_id Optional[str] ➖ N/A
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.ListActionsResponse

Errors

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

create

Create an action.

Example Usage

from moderation_api import ModerationAPI
import os


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

    res = ma_client.actions.create(name="Suspend for 24 hours", key="suspend-24h", type_="AUTHOR_BLOCK_TEMP", built_in=False, queue_behaviour="REMOVE", position="ALL_QUEUES", value_required=False, free_text=False)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
name str ✔️ The name of the action.
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.
key OptionalNullable[str] ➖ User defined key of the action.
description OptionalNullable[str] ➖ The description of the action.
type OptionalNullable[models.CreateActionTypeRequest] ➖ The type of the action.
built_in OptionalNullable[bool] ➖ Whether the action is a built-in action or a custom one.
queue_behaviour Optional[models.CreateActionQueueBehaviourRequest] ➖ Whether the action resolves and removes the item, unresolves and re-add it to the queue, or does not change the resolve status.
filter_in_queue_ids List[str] ➖ The IDs of the queues the action is available in.
position Optional[models.CreateActionPositionRequest] ➖ Show the action in all queues, selected queues or no queues (to use via API only).
possible_values List[models.CreateActionPossibleValueRequest] ➖ The possible values of the action. The user will be prompted to select one of these values when executing the action.
value_required Optional[bool] ➖ Whether the action requires a value to be executed.
free_text Optional[bool] ➖ Whether the action allows any text to be entered as a value or if it must be one of the possible values.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.CreateActionResponse

Errors

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

retrieve

Get an action 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.actions.retrieve(id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
id str ✔️ The ID of the action 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.GetActionResponse

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 */*

update

Update an action.

Example Usage

from moderation_api import ModerationAPI
import os


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

    res = ma_client.actions.update(id="<id>", built_in=False, queue_behaviour="NO_CHANGE", position="ALL_QUEUES", value_required=False, free_text=False)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
id str ✔️ The ID of the action 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.
key OptionalNullable[str] ➖ User defined key of the action.
name Optional[str] ➖ The name of the action.
description OptionalNullable[str] ➖ The description of the action.
type OptionalNullable[models.UpdateActionTypeRequest] ➖ The type of the action.
built_in OptionalNullable[bool] ➖ Whether the action is a built-in action or a custom one.
queue_behaviour Optional[models.UpdateActionQueueBehaviourRequest] ➖ Whether the action resolves and removes the item, unresolves and re-add it to the queue, or does not change the resolve status.
filter_in_queue_ids List[str] ➖ The IDs of the queues the action is available in.
position Optional[models.UpdateActionPositionRequest] ➖ Show the action in all queues, selected queues or no queues (to use via API only).
possible_values List[models.UpdateActionPossibleValueRequest] ➖ The possible values of the action. The user will be prompted to select one of these values when executing the action.
value_required Optional[bool] ➖ Whether the action requires a value to be executed.
free_text Optional[bool] ➖ Whether the action allows any text to be entered as a value or if it must be one of the possible values.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.UpdateActionResponse

Errors

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

delete

Delete an action and all of its webhooks.

Example Usage

from moderation_api import ModerationAPI
import os


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

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

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
id str ✔️ The ID of the action 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.DeleteActionResponse

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 */*

execute

Execute a moderation action on one or more content items.

Example Usage

from moderation_api import ModerationAPI
import os


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

    res = ma_client.actions.execute(action_key="suspend-24h", author_ids=[
        "user-1092",
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
action_key str ✔️ ID or key of the action to execute
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.
content_ids List[str] ➖ IDs of the content items to apply the action to. Provide this or authorIds.
author_ids List[str] ➖ IDs of the authors to apply the action to. Provide this or contentIds.
value Optional[str] ➖ Optional value to provide with the action
queue_id Optional[str] ➖ Optional queue ID if the action is queue-specific
duration Optional[float] ➖ Optional duration in milliseconds for actions with timeouts
moderator Optional[str] ➖ The user ID or email of the organization member who made the decision. The action is recorded as theirs.
create_casebook_case Optional[bool] ➖ Record an allow or reject decision as a casebook case. Defaults to true when moderator is set, else false. Without moderator, the case is recorded as System.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.ExecuteActionResponse

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 */*