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

# Create Campaign

> Create a new email campaign from a generated email. Use emailId for the exact generated email, especially series slots. Requires API key with campaign:write.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/campaigns
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: Project Editing
    description: Edit project assets, logos, images, and knowledge base entries
paths:
  /v1/campaigns:
    post:
      tags:
        - Campaigns
      summary: Create Campaign
      description: >-
        Create a new email campaign from a generated email. Use emailId for the
        exact generated email, especially series slots. Requires API key with
        campaign:write.
      operationId: CreateCampaign
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateCampaignRequest'
      responses:
        '200':
          description: Campaign created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCampaign'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
      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.campaigns.create({
              projectId: 'PROJECT_ID',
              name: 'Investor Update',
              conversationId: 'CONVERSATION_ID',
              emailId: 'EMAIL_ID',
              from: 'hello@yourbrand.migma.email',
              fromName: 'Your Brand',
              recipientType: 'tag',
              recipientId: 'TAG_ID'
            });
components:
  schemas:
    CreateCampaignRequest:
      type: object
      required:
        - projectId
        - name
        - conversationId
        - from
        - fromName
        - recipientType
        - recipientId
      properties:
        projectId:
          type: string
          description: Project ID
        name:
          type: string
          description: Campaign name
        conversationId:
          type: string
          description: Conversation ID that owns the generated email
        emailId:
          type: string
          description: >-
            Generated email ID from result.emails[].emailId. Recommended for
            series slots.
        subject:
          type: string
          description: Email subject (auto-populated from conversation if omitted)
        preheaderText:
          type: string
          description: Preheader text
        from:
          type: string
          format: email
          description: Sender email address
        fromName:
          type: string
          description: Sender display name
        replyTo:
          type: string
          format: email
          description: Reply-to address
        recipientType:
          type: string
          enum:
            - audience
            - tag
          description: Send to a segment (audience) or tag
        recipientId:
          type: string
          description: Segment or tag ID
        topicId:
          type: string
          description: Topic ID for preference filtering
        providerType:
          type: string
          enum:
            - ses
            - resend
            - sendgrid
            - mailgun
            - migma
          description: 'Email provider (default: migma)'
        variables:
          type: object
          additionalProperties: true
          description: Template variables
    ApiResponseCampaign:
      allOf:
        - $ref: '#/components/schemas/ApiResponse'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/Campaign'
    ApiResponse:
      type: object
      properties:
        success:
          type: boolean
        data:
          nullable: true
        error:
          type: string
          nullable: true
      required:
        - success
    Campaign:
      type: object
      properties:
        id:
          type: string
        projectId:
          type: string
        name:
          type: string
        conversationId:
          type: string
        emailId:
          type: string
          nullable: true
          description: >-
            Generated email ID when the campaign was created from a specific
            email.
        subject:
          type: string
        preheaderText:
          type: string
          nullable: true
        from:
          type: string
          format: email
        fromName:
          type: string
        replyTo:
          type: string
          nullable: true
        recipientType:
          type: string
          enum:
            - audience
            - tag
        recipientId:
          type: string
        topicId:
          type: string
          nullable: true
        estimatedRecipients:
          type: integer
          nullable: true
        providerType:
          type: string
          enum:
            - ses
            - resend
            - sendgrid
            - mailgun
            - migma
        variables:
          type: object
          nullable: true
          additionalProperties: true
        status:
          type: string
          enum:
            - draft
            - pending_review
            - scheduled
            - sending
            - throttled
            - sent
            - failed
            - cancelled
        scheduledAt:
          type: string
          format: date-time
          nullable: true
        scheduledTimezone:
          type: string
          nullable: true
        batchId:
          type: string
          nullable: true
        sentAt:
          type: string
          format: date-time
          nullable: true
        completedAt:
          type: string
          format: date-time
          nullable: true
        error:
          type: string
          nullable: true
        triggeredBy:
          type: string
          enum:
            - manual
            - api
            - automation
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
    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'
    Forbidden:
      description: Forbidden - Missing required permissions or access denied
      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.

````