> ## 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.

# Membuat task action Midjourney

> Gunakan CometAPI POST /mj/submit/action untuk menerapkan action Midjourney—upscale, variation, reroll, zoom, dan lainnya—pada gambar yang dihasilkan.

Gunakan endpoint ini setelah task Midjourney mengembalikan tombol action. Endpoint ini memulai task turunan baru seperti upscale, variation, reroll, zoom, atau pan.

## Anda memerlukan dua nilai

* `taskId` dari task Midjourney asli atau yang paling baru
* `customId` dari array `buttons` terbaru yang dikembalikan oleh [Fetch Single Task](./task-fetching-api/fetch-single-task)

<Warning>
  `customId` tidak bersifat stabil. Jangan pernah melakukan hardcode padanya. Selalu baca nilainya dari respons polling terbaru.
</Warning>

## Action umum

* `U1` hingga `U4`: upscale satu gambar dari grid
* `V1` hingga `V4`: menghasilkan variation dari satu posisi gambar
* Reroll: menghasilkan ulang seluruh grid
* Zoom dan Pan: memperluas komposisi yang ada

## Setelah Anda mengirimkan action

<Steps>
  <Step title="Buat task lanjutan">
    Kirim `taskId` dan `customId`, lalu simpan task id baru yang dikembalikan.
  </Step>

  <Step title="Poll task baru">
    Lakukan kueri ke [Fetch Single Task](./task-fetching-api/fetch-single-task) lagi sampai action selesai.
  </Step>

  <Step title="Tangani action khusus modal">
    Jika task baru mencapai `MODAL`, lanjutkan dengan [Modal](./modal) untuk memberikan input tambahan.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/image/midjourney/post-action.openapi.json POST /mj/submit/action
openapi: 3.1.0
info:
  title: Action API
  version: 1.0.0
  description: >-
    Create a Midjourney follow-up task such as upscale, variation, reroll, zoom,
    or pan using the latest button customId from the fetch response.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /mj/submit/action:
    post:
      summary: Create a Midjourney follow-up action task
      operationId: action
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - customId
                - taskId
              properties:
                customId:
                  type: string
                  description: >-
                    Action id taken from the latest `buttons` array returned by
                    the fetch endpoint.
                taskId:
                  type: string
                  description: Midjourney task id you want to continue from.
                state:
                  type: string
                  description: >-
                    Custom state string. Returned as-is in the task result and
                    webhook callback for your own tracking.
                enableRemix:
                  type: boolean
                  description: >-
                    Whether to force remix mode when the current action supports
                    it.
                chooseSameChannel:
                  type: boolean
                  description: >-
                    Whether to prefer the same provider account used by the
                    current task.
              default:
                customId: MJ::JOB::variation::3::example
                taskId: '1773314942177684'
                enableRemix: false
            examples:
              Upscale U1:
                summary: Upscale the first image (U1)
                value:
                  taskId: <task_id>
                  customId: MJ::JOB::upsample::1::<custom_id_hash>
              Vary Region:
                summary: >-
                  Open the Vary (Region) modal; the response returns code 21 and
                  a task id to use with /mj/submit/modal
                value:
                  taskId: <task_id>
                  customId: MJ::Inpaint::1::<custom_id_hash>::SOLO
      responses:
        '200':
          description: Action task accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - description
                  - result
                properties:
                  code:
                    type: integer
                    description: >-
                      Submission status code. `1` = submitted successfully
                      (`result` carries the task id). `21` = the action opened a
                      confirmation modal; continue with `/mj/submit/modal` using
                      the returned task id. `4` = parameter error; `description`
                      explains the cause.
                  description:
                    type: string
                  result:
                    type: string
                    description: New Midjourney task id created for the action.
                  properties:
                    type: object
                    properties:
                      numberOfQueues:
                        type: integer
                      discordInstanceId:
                        type: string
                      discordChannelId:
                        type: string
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/mj/submit/action \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "taskId": "<task_id>",
                  "customId": "MJ::JOB::upsample::1::<custom_id_hash>"
                }'
        - lang: Python
          label: Default
          source: >
            import os

            import requests


            response = requests.post(
                "https://api.cometapi.com/mj/submit/action",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                        "taskId": "<task_id>",
                        "customId": "MJ::JOB::upsample::1::<custom_id_hash>"
                },
            )


            task = response.json()

            print(task["code"], task.get("result"))  # code 1 means submitted;
            result is the task id
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/mj/submit/action", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                        "taskId": "<task_id>",
                        "customId": "MJ::JOB::upsample::1::<custom_id_hash>"
                    }),
            });


            const task = await response.json();

            console.log(task.code, task.result); // code 1 means submitted;
            result is the task id
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````