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

# Import HTML Email (Async)

> Convert existing HTML or .eml into editable Migma emails using the same HTML to Email path as Create. Requires API key with email:write. Provide html for one file or htmls (1-12). Optional instruction describes keep-as-is vs apply-brand. Returns immediately with a conversationId and pending status. Use GET /v1/projects/emails/{conversationId}/status to retrieve production HTML, screenshots, and per-email IDs. Do not send HTML to generate.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/projects/emails/import-html
openapi: 3.1.0
info:
  title: Migma.ai API (v1)
  description: >-
    API for managing brands, contacts, email generation, sending, and
    integrations.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.migma.ai
    description: Production
security:
  - apiKeyAuth: []
tags:
  - name: Projects/Brands
    description: Manage projects (brands) and import from websites
  - name: Contacts
    description: Manage your contacts, segments, tags, and topics
  - name: Segments
    description: Create and manage dynamic contact segments
  - name: Tags
    description: Organize contacts with tags
  - name: Topics
    description: Manage subscription topics and preferences
  - name: Emails
    description: Generate, send, and export emails
  - name: Email Validation
    description: Validate email content for compatibility and deliverability
  - name: Email Previews
    description: Preview emails across devices and email clients
  - name: Domains
    description: Manage sending domains and verification
  - name: Webhooks
    description: Manage webhook endpoints for real-time event notifications
  - name: Events
    description: Record customer events and conversions
  - name: Integrations
    description: Third-party platform integrations
  - name: Campaigns
    description: Create, schedule, send, and manage email campaigns
  - name: Billing
    description: View your plan and credits and create billing links
  - name: Project Editing
    description: Edit project assets, logos, images, and knowledge base entries
paths:
  /v1/projects/emails/import-html:
    post:
      tags:
        - Emails
      summary: Import HTML Email (Async)
      description: >-
        Convert existing HTML or .eml into editable Migma emails using the same
        HTML to Email path as Create. Requires API key with email:write. Provide
        html for one file or htmls (1-12). Optional instruction describes
        keep-as-is vs apply-brand. Returns immediately with a conversationId and
        pending status. Use GET /v1/projects/emails/{conversationId}/status to
        retrieve production HTML, screenshots, and per-email IDs. Do not send
        HTML to generate.
      operationId: ImportHtmlEmail
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImportHtmlEmailRequest'
      responses:
        '200':
          description: HTML import started
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGenerateEmail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
      x-codeSamples:
        - lang: javascript
          label: Node.js SDK
          source: |-
            import Migma from 'migma';

            const migma = new Migma('YOUR_API_KEY');

            const { data, error } = await migma.emails.importHtml({
              projectId: 'PROJECT_ID',
              html: '<html><body>Welcome</body></html>',
              name: 'welcome.html',
              instruction: 'Keep this exactly as-is'
            });

            // Poll /status or use importHtmlAndWait() to get result.emails[].
components:
  schemas:
    ImportHtmlEmailRequest:
      type: object
      properties:
        projectId:
          type: string
          pattern: ^[0-9a-fA-F]{24}$
        html:
          type: string
          description: Single HTML or .eml source. Provide html or htmls, not both.
        name:
          type: string
          maxLength: 200
          description: Filename for a single html paste.
        htmls:
          type: array
          minItems: 1
          maxItems: 12
          items:
            $ref: '#/components/schemas/ImportHtmlEmailFile'
          description: Multiple HTML or .eml files. One file becomes one canvas slot.
        instruction:
          type: string
          maxLength: 20000
          description: Natural-language conversion instruction (keep as-is vs apply brand).
        languages:
          type: array
          items:
            type: string
          maxItems: 5
        visibility:
          type: string
          enum:
            - private
            - unlisted
            - public
          default: unlisted
        generateMedia:
          type: boolean
          description: >-
            Generate AI media for missing images. Defaults to the project
            setting, then true.
      required:
        - projectId
    ApiResponseGenerateEmail:
      allOf:
        - $ref: '#/components/schemas/ApiResponse'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/GenerateEmailData'
    ImportHtmlEmailFile:
      type: object
      properties:
        name:
          type: string
          maxLength: 200
          description: Filename, e.g. welcome.html or message.eml
        source:
          type: string
          description: HTML document or raw .eml source. Max 250KB per file.
      required:
        - name
        - source
    ApiResponse:
      type: object
      properties:
        success:
          type: boolean
        data:
          nullable: true
        error:
          type: string
          nullable: true
      required:
        - success
    GenerateEmailData:
      type: object
      properties:
        conversationId:
          type: string
          description: The conversation ID to check status and retrieve results
        status:
          type: string
          enum:
            - pending
          description: Initial status is always pending
        message:
          type: string
          description: Information message about the generation process
        link:
          type: string
          format: uri
          description: >-
            Direct link to view the generated email. Unlisted and public
            generations return https://migma.ai/share/{conversationId}; private
            generations return https://migma.ai/chat?c={conversationId}.
        count:
          type: integer
          description: Requested email count, when provided.
        referenceId:
          type: string
          description: Reference conversation used for remixing, when provided.
      required:
        - conversationId
        - status
        - message
        - link
    ApiError:
      type: object
      properties:
        success:
          type: boolean
          default: false
        error:
          type: string
        code:
          type: string
          description: >-
            Machine-readable error code (e.g., IDEMPOTENCY_CONFLICT,
            DOMAIN_CLAIMABLE).
        data:
          type: object
          description: >-
            Additional structured context for the error, such as the affected
            domain.
          additionalProperties: true
      required:
        - success
        - error
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Use 'Authorization: Bearer YOUR_API_KEY' where
        YOUR_API_KEY is obtained from the Migma dashboard under Settings →
        Developers → API Keys.

````