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

# 列出 Midjourney 任务

> POST /mj/task/list-by-condition 通过筛选条件列出 Midjourney 任务，用于获取一个或多个任务的状态，包括进度和结果。

当你需要批量检索 Midjourney 任务，而不是一次轮询一个 task id 时，请使用此端点。

## 何时使用

* 你正在同时跟踪多个 Midjourney 任务
* 你希望按任务状态、提交时间窗口或其他服务端条件进行筛选
* 你需要的是仪表板或对账任务，而不是交互式的单任务轮询

## 查询模式

<Steps>
  <Step title="对关键路径使用单任务轮询">
    对于一个活跃任务，优先使用 [获取单个任务](./fetch-single-task)，因为它更简单也更快。
  </Step>

  <Step title="对批量检查使用基于条件的列表查询">
    当你需要在一次请求中检查多个 Midjourney 任务时，通过此端点发送你的筛选条件。
  </Step>

  <Step title="继续跟进值得关注的任务">
    当批量结果显示某些任务需要更深入的检查或继续处理时，切换回 [获取单个任务](./fetch-single-task) 和 [Action](../action)。
  </Step>
</Steps>

<Tip>
  将此路由用于监控和对账任务；主要的交互式轮询路径请使用 [获取单个任务](./fetch-single-task)。
</Tip>


## OpenAPI

````yaml api/openapi/image/midjourney/task-fetching-api/post-list-by-condition.openapi.json POST /mj/task/list-by-condition
openapi: 3.1.0
info:
  title: List by Condition API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /mj/task/list-by-condition:
    post:
      summary: List by Condition
      operationId: list_by_condition
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - ids
              properties:
                ids:
                  type: array
                  description: >-
                    Array of Midjourney task ids to retrieve. Returns the
                    current status and result for each.
                  items:
                    type: string
                  default:
                    - example
              default:
                ids:
                  - example
            examples:
              Default:
                summary: Fetch several tasks by id
                value:
                  ids:
                    - <task_id>
                    - <task_id>
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    action:
                      type: string
                      description: >-
                        Task type: `IMAGINE`, `UPSCALE`, `VARIATION`,
                        `DESCRIBE`, `BLEND`, `VIDEO`, or another action name.
                    buttons:
                      type: array
                      items:
                        type: object
                        properties:
                          customId:
                            type: string
                          emoji:
                            type: string
                          label:
                            type: string
                          style:
                            type: integer
                          type:
                            type: integer
                      description: >-
                        Action buttons available on the finished task. Send a
                        button's `customId` together with this task's id to
                        `/mj/submit/action` to upscale, vary, zoom, or pan.
                    description:
                      type: string
                      description: Human-readable submission status message.
                    failReason:
                      type: string
                      description: Failure reason when `status` is `FAILURE`.
                    finishTime:
                      type: integer
                      description: Completion time as a Unix timestamp in milliseconds.
                    id:
                      type: string
                      description: Task id.
                    imageUrl:
                      type: string
                      description: >-
                        Stable CometAPI-proxied image link
                        (`https://api.cometapi.com/mj/image/{id}`). Prefer this
                        link; entries in `image_urls` point at provider storage
                        and can expire.
                    progress:
                      type: string
                      description: >-
                        Progress percentage string such as `58%` while the task
                        runs and `100%` when finished.
                    prompt:
                      type: string
                      description: Original prompt as submitted.
                    promptEn:
                      type: string
                      description: >-
                        Prompt after translation to the provider language. For
                        `DESCRIBE` tasks, the extracted prompt suggestions
                        arrive here.
                    properties:
                      type: object
                      properties: {}
                      description: Additional task metadata, such as `finalPrompt`.
                    startTime:
                      type: integer
                      description: >-
                        Processing start time as a Unix timestamp in
                        milliseconds.
                    state:
                      type: string
                      description: >-
                        Custom state string echoed back from the submission for
                        your own tracking.
                    status:
                      type: string
                      description: >-
                        Task lifecycle state: `NOT_START`, `SUBMITTED`,
                        `IN_PROGRESS`, `SUCCESS`, or `FAILURE`.
                    submitTime:
                      type: integer
                      description: Submission time as a Unix timestamp in milliseconds.
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/mj/task/list-by-condition \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "ids": ["<task_id>", "<task_id>"]
              }'
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/mj/task/list-by-condition",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={"ids": ["<task_id>", "<task_id>"]},
            )

            for task in response.json():
                print(task["id"], task["action"], task["status"], task.get("progress"))
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/mj/task/list-by-condition", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({ ids: ["<task_id>", "<task_id>"] }),
            });


            for (const task of await response.json()) {
                console.log(task.id, task.action, task.status, task.progress);
            }
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````