import { ModerationApi } from "@moderation-api/sdk";
const moderationApi = new ModerationApi({
secretKey: process.env["MODAPI_SECRET_KEY"] ?? "",
});
async function run() {
const result = await moderationApi.webhooks.create({
name: "Moderation events",
url: "https://example.com/webhooks/moderation",
eventTypes: [
"QUEUE_ITEM_REJECTED",
"AUTHOR_BLOCKED",
],
});
console.log(result);
}
run();
import os
from moderation_api import ModerationAPI
with ModerationAPI(
secret_key=os.environ["MODAPI_SECRET_KEY"],
) as moderation_api:
res = moderation_api.webhooks.create(name="Moderation events", url="https://example.com/webhooks/moderation", event_types=[
"QUEUE_ITEM_REJECTED",
"AUTHOR_BLOCKED",
])
# Handle response
print(res)
declare(strict_types=1);
require 'vendor/autoload.php';
use ModerationApi;
use ModerationApi\Models\Operations;
$sdk = ModerationApi\ModerationApi::builder()
->setSecurity(
getenv('MODAPI_SECRET_KEY')
)
->build();
$body = new Operations\CreateWebhookRequestBody(
name: 'Moderation events',
url: 'https://example.com/webhooks/moderation',
eventTypes: [
Operations\CreateWebhookEventTypeRequest::QueueItemRejected,
Operations\CreateWebhookEventTypeRequest::AuthorBlocked,
],
);
$response = $sdk->webhooks->create(
body: $body
);
if ($response->object !== null) {
// handle response
}
require 'moderation_api'
Models = ::ModerationApi::Models
s = ::ModerationApi::ModerationApi.new(
secret_key: ENV.fetch('MODAPI_SECRET_KEY')
)
res = s.webhooks.create(body: Models::Operations::CreateWebhookRequestBody.new(
name: 'Moderation events',
url: 'https://example.com/webhooks/moderation',
event_types: [
Models::Operations::CreateWebhookEventTypeRequest::QUEUE_ITEM_REJECTED,
Models::Operations::CreateWebhookEventTypeRequest::AUTHOR_BLOCKED,
]
))
unless res.object.nil?
# handle response
end
modapi webhooks create --secret-key "$MODAPI_SECRET_KEY" --name 'Moderation events' --url 'https://example.com/webhooks/moderation' --event-types '["QUEUE_ITEM_REJECTED","AUTHOR_BLOCKED"]'
{
"id": "<string>",
"name": "<string>",
"url": "<string>",
"eventTypes": [],
"payloadVersion": "V1",
"createdAt": "<string>",
"description": "<string>"
}{
"type": "invalid_request_error",
"code": "invalid_request",
"message": "Invalid input data",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "authentication_error",
"code": "unauthorized",
"message": "Authorization not provided",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "rate_limit_error",
"code": "rate_limit_exceeded",
"message": "Rate limit exceeded",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}Create a webhook
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).
import { ModerationApi } from "@moderation-api/sdk";
const moderationApi = new ModerationApi({
secretKey: process.env["MODAPI_SECRET_KEY"] ?? "",
});
async function run() {
const result = await moderationApi.webhooks.create({
name: "Moderation events",
url: "https://example.com/webhooks/moderation",
eventTypes: [
"QUEUE_ITEM_REJECTED",
"AUTHOR_BLOCKED",
],
});
console.log(result);
}
run();
import os
from moderation_api import ModerationAPI
with ModerationAPI(
secret_key=os.environ["MODAPI_SECRET_KEY"],
) as moderation_api:
res = moderation_api.webhooks.create(name="Moderation events", url="https://example.com/webhooks/moderation", event_types=[
"QUEUE_ITEM_REJECTED",
"AUTHOR_BLOCKED",
])
# Handle response
print(res)
declare(strict_types=1);
require 'vendor/autoload.php';
use ModerationApi;
use ModerationApi\Models\Operations;
$sdk = ModerationApi\ModerationApi::builder()
->setSecurity(
getenv('MODAPI_SECRET_KEY')
)
->build();
$body = new Operations\CreateWebhookRequestBody(
name: 'Moderation events',
url: 'https://example.com/webhooks/moderation',
eventTypes: [
Operations\CreateWebhookEventTypeRequest::QueueItemRejected,
Operations\CreateWebhookEventTypeRequest::AuthorBlocked,
],
);
$response = $sdk->webhooks->create(
body: $body
);
if ($response->object !== null) {
// handle response
}
require 'moderation_api'
Models = ::ModerationApi::Models
s = ::ModerationApi::ModerationApi.new(
secret_key: ENV.fetch('MODAPI_SECRET_KEY')
)
res = s.webhooks.create(body: Models::Operations::CreateWebhookRequestBody.new(
name: 'Moderation events',
url: 'https://example.com/webhooks/moderation',
event_types: [
Models::Operations::CreateWebhookEventTypeRequest::QUEUE_ITEM_REJECTED,
Models::Operations::CreateWebhookEventTypeRequest::AUTHOR_BLOCKED,
]
))
unless res.object.nil?
# handle response
end
modapi webhooks create --secret-key "$MODAPI_SECRET_KEY" --name 'Moderation events' --url 'https://example.com/webhooks/moderation' --event-types '["QUEUE_ITEM_REJECTED","AUTHOR_BLOCKED"]'
{
"id": "<string>",
"name": "<string>",
"url": "<string>",
"eventTypes": [],
"payloadVersion": "V1",
"createdAt": "<string>",
"description": "<string>"
}{
"type": "invalid_request_error",
"code": "invalid_request",
"message": "Invalid input data",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "authentication_error",
"code": "unauthorized",
"message": "Authorization not provided",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}{
"type": "rate_limit_error",
"code": "rate_limit_exceeded",
"message": "Rate limit exceeded",
"request_id": "h8fkz6kkzoa446ffve37atys",
"doc_url": "<string>",
"issues": [
{
"message": "<string>",
"path": [
"<string>"
],
"code": "<string>"
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
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.
Body
The webhook's name, used to identify it in the dashboard
1The webhook's URL. We'll call this URL when an event occurs.
Event types this webhook subscribes to. One webhook URL receives all events you list here.
1QUEUE_ITEM_NEW, QUEUE_ITEM_COMPLETED, QUEUE_ITEM_ACTION, QUEUE_ITEM_REJECTED, QUEUE_ITEM_ALLOWED, AUTHOR_BLOCKED, AUTHOR_UNBLOCKED, AUTHOR_SUSPENDED, AUTHOR_UPDATED, AUTHOR_TRUST_LEVEL_CHANGED, AUTHOR_ACTION The webhook's description
Response
Webhook created successfully
The ID of the webhook.
The webhook's name.
The URL we call when a subscribed event occurs.
Event types this webhook subscribes to. Empty for legacy v1 webhooks, which subscribe via their single deprecated type instead.
QUEUE_ITEM_NEW, QUEUE_ITEM_COMPLETED, QUEUE_ITEM_ACTION, QUEUE_ITEM_REJECTED, QUEUE_ITEM_ALLOWED, AUTHOR_BLOCKED, AUTHOR_UNBLOCKED, AUTHOR_SUSPENDED, AUTHOR_UPDATED, AUTHOR_TRUST_LEVEL_CHANGED, AUTHOR_ACTION Payload envelope version. V2 is the Stripe-style envelope; V1 is the legacy flat shape and is read-only via this API.
V1, V2 The date the webhook was created.
The webhook's description.
Was this page helpful?