> ## Documentation Index
> Fetch the complete documentation index at: https://docs.moderationapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute moderation action

> Execute a moderation action on one or more content items.

<RequestExample>
  ```bash cURL theme={"theme":"nord"}
  curl -X POST 'https://api.moderationapi.com/v1/actions/execute' \
    -H 'Authorization: Bearer <token>' \
    -H 'Content-Type: application/json' \
    -d '{
      "contentIds": [
        "60c9e1c0e4e7e1001c7a0e1e",
        "60c9e1c0e4e7e1001c7a0e1f"
      ],
      "actionId": "suspend-author",
      "value": "Spam"
    }'
  ```

  ```javascript Node.js theme={"theme":"nord"}
  import ModerationAPI from "@moderation-api/sdk";

  // Uses environment variable MODAPI_SECRET_KEY
  const moderationApi = new ModerationAPI();

  // Or pass key explicitly
  // const moderationApi = new ModerationAPI({ secretKey: '<token>' });

  await moderationApi.actions.execute({
    contentIds: ["60c9e1c0e4e7e1001c7a0e1e", "60c9e1c0e4e7e1001c7a0e1f"],
    actionId: "suspend-author",
    value: "Spam",
  });
  ```

  ```ruby Ruby theme={"theme":"nord"}
  require 'moderation_api'

  ModerationApi.configure do |config|
    config.access_token = '<token>'
  end

  api = ModerationApi::QueueActionsApi.new
  api.actions_execute(
    content_ids: [
      '60c9e1c0e4e7e1001c7a0e1e',
      '60c9e1c0e4e7e1001c7a0e1f'
    ],
    action_id: 'suspend-author',
    value: 'Spam'
  )
  ```

  ```python Python theme={"theme":"nord"}
  import requests

  url = "https://api.moderationapi.com/v1/actions/execute"
  headers = {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
  }
  payload = {
      "contentIds": [
          "60c9e1c0e4e7e1001c7a0e1e",
          "60c9e1c0e4e7e1001c7a0e1f"
      ],
      "actionId": "suspend-author",
      "value": "Spam"
  }

  response = requests.post(url, headers=headers, json=payload)
  ```

  ```php PHP theme={"theme":"nord"}
  <?php
  $url = "https://api.moderationapi.com/v1/actions/execute";
  $headers = array(
      "Authorization: Bearer <token>",
      "Content-Type: application/json"
  );
  $data = array(
      "contentIds" => array(
          "60c9e1c0e4e7e1001c7a0e1e",
          "60c9e1c0e4e7e1001c7a0e1f"
      ),
      "actionId" => "suspend-author",
      "value" => "Spam"
  );

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  $response = curl_exec($ch);
  curl_close($ch);

  $result = json_decode($response, true);
  ?>
  ```

  ```java Java theme={"theme":"nord"}
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.URI;

  String url = "https://api.moderationapi.com/v1/actions/execute";
  String requestBody = """
      {
          "contentIds": [
              "60c9e1c0e4e7e1001c7a0e1e",
              "60c9e1c0e4e7e1001c7a0e1f"
          ],
          "actionId": "suspend-author",
          "value": "Spam"
      }
      """;

  HttpClient client = HttpClient.newHttpClient();
  HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create(url))
      .header("Authorization", "Bearer <token>")
      .header("Content-Type", "application/json")
      .POST(HttpRequest.BodyPublishers.ofString(requestBody))
      .build();

  HttpResponse<String> response = client.send(request,
      HttpResponse.BodyHandlers.ofString());
  System.out.println(response.body());
  ```

  ```go Go theme={"theme":"nord"}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "net/http"
  )

  func main() {
      url := "https://api.moderationapi.com/v1/actions/execute"
      data := map[string]interface{}{
          "contentIds": []string{
              "60c9e1c0e4e7e1001c7a0e1e",
              "60c9e1c0e4e7e1001c7a0e1f",
          },
          "actionId": "suspend-author",
          "value":    "Spam",
      }

      jsonData, _ := json.Marshal(data)
      req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
      req.Header.Set("Authorization", "Bearer <token>")
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      var result map[string]interface{}
      json.NewDecoder(resp.Body).Decode(&result)
      fmt.Println(result)
  }
  ```
</RequestExample>


## OpenAPI

````yaml post /actions/execute
openapi: 3.1.0
info:
  title: Moderation API
  description: API for automated content moderation
  version: 1.1.0
servers:
  - url: https://api.moderationapi.com/v1
security: []
tags:
  - name: Actions
  - name: Queues
  - name: Webhooks
  - name: Wordlist
  - name: UserReports
externalDocs:
  url: https://docs.moderationapi.com
paths:
  /actions/execute:
    post:
      tags:
        - Actions
      summary: Execute moderation action
      description: Execute a moderation action on one or more content items.
      operationId: actions-execute
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                actionKey:
                  type: string
                  description: ID or key of the action to execute
                contentIds:
                  description: >-
                    IDs of the content items to apply the action to. Provide
                    this or authorIds.
                  type: array
                  items:
                    type: string
                authorIds:
                  description: >-
                    IDs of the authors to apply the action to. Provide this or
                    contentIds.
                  type: array
                  items:
                    type: string
                value:
                  description: Optional value to provide with the action
                  type: string
                queueId:
                  description: Optional queue ID if the action is queue-specific
                  type: string
                duration:
                  description: Optional duration in milliseconds for actions with timeouts
                  type: number
                  minimum: 0
              required:
                - actionKey
              description: Input parameters
      responses:
        '200':
          description: Action executed successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: Whether the action was executed successfully
                required:
                  - success
                additionalProperties: false
                description: Execution result
        '400':
          description: Invalid input data
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.BAD_REQUEST'
        '401':
          description: Authorization not provided
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.UNAUTHORIZED'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error.NOT_FOUND'
      security:
        - Authorization: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import ModerationAPI from '@moderation-api/sdk';


            const client = new ModerationAPI({
              secretKey: process.env['MODAPI_SECRET_KEY'], // This is the default and can be omitted
            });


            const response = await client.actions.execute.execute({ actionKey:
            'actionKey' });


            console.log(response.success);
        - lang: Python
          source: |-
            import os
            from moderation_api import ModerationAPI

            client = ModerationAPI(
                secret_key=os.environ.get("MODAPI_SECRET_KEY"),  # This is the default and can be omitted
            )
            response = client.actions.execute.execute(
                action_key="actionKey",
            )
            print(response.success)
        - lang: Ruby
          source: >-
            require "moderation_api"


            moderation_api = ModerationAPI::Client.new(secret_key: "My Secret
            Key")


            response = moderation_api.actions.execute.execute(action_key:
            "actionKey")


            puts(response)
components:
  schemas:
    error.BAD_REQUEST:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Invalid input data
        code:
          type: string
          description: The error code
          example: BAD_REQUEST
        issues:
          description: An array of issues that were responsible for the error
          example: []
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
            additionalProperties: false
      required:
        - message
        - code
      additionalProperties: false
      title: Invalid input data error (400)
      description: The error information
      example:
        code: BAD_REQUEST
        message: Invalid input data
        issues: []
    error.UNAUTHORIZED:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Authorization not provided
        code:
          type: string
          description: The error code
          example: UNAUTHORIZED
        issues:
          description: An array of issues that were responsible for the error
          example: []
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
            additionalProperties: false
      required:
        - message
        - code
      additionalProperties: false
      title: Authorization not provided error (401)
      description: The error information
      example:
        code: UNAUTHORIZED
        message: Authorization not provided
        issues: []
    error.NOT_FOUND:
      type: object
      properties:
        message:
          type: string
          description: The error message
          example: Not found
        code:
          type: string
          description: The error code
          example: NOT_FOUND
        issues:
          description: An array of issues that were responsible for the error
          example: []
          type: array
          items:
            type: object
            properties:
              message:
                type: string
            required:
              - message
            additionalProperties: false
      required:
        - message
        - code
      additionalProperties: false
      title: Not found error (404)
      description: The error information
      example:
        code: NOT_FOUND
        message: Not found
        issues: []
  securitySchemes:
    Authorization:
      type: http
      scheme: bearer

````