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

# Create a new campaign

> Create a campaign. Requires a SERVER API token. The account_id is derived from the access token and must not be sent in the request body. The selected campaign type is sent in the type query parameter and determines the body validation. Campaign rules must include at least one main/referrer rule. Create rejects past start dates, start dates one year or more in the future, end dates before start_date, and end dates one year or more after start_date.



## OpenAPI

````yaml POST /campaigns
openapi: 3.0.1
info:
  title: Masivo's REST API
  description: Learn how to use Masivo's REST API
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://app.masivo.ai/api/storefront/v1
security:
  - bearerAuth: []
paths:
  /campaigns:
    post:
      description: >-
        Create a campaign. Requires a SERVER API token. The account_id is
        derived from the access token and must not be sent in the request body.
        The selected campaign type is sent in the type query parameter and
        determines the body validation. Campaign rules must include at least one
        main/referrer rule. Create rejects past start dates, start dates one
        year or more in the future, end dates before start_date, and end dates
        one year or more after start_date.
      parameters:
        - in: query
          name: type
          description: >-
            The campaign type to create. The request body must match the
            selected campaign form payload.
          required: true
          schema:
            $ref: '#/components/schemas/CampaignType'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CampaignInsert'
      responses:
        '201':
          description: Campaign created
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Campaign'
        '403':
          description: Forbidden, CLIENT API tokens cannot create campaigns
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: Invalid campaign
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CampaignType:
      type: string
      description: The campaign type
      enum:
        - BEHAVIOR
        - COUPONS
        - PUNCH_CARDS
        - REFERRALS
    CampaignInsert:
      type: object
      description: >-
        Storefront campaign write payload. Send the campaign type as the
        required type query parameter, not in the body. The body mirrors the
        dashboard campaign form for that type. account_id is derived from the
        SERVER token. Common validation: rules must contain at least one
        main/referrer rule, metadata must be a JSON object encoded as a string,
        budget must be at least 1, labels and platforms use dashboard select
        values, content stores optional CMS template field values, and dates
        must follow the campaign date restrictions.
      additionalProperties: true
      properties:
        brand_id:
          type: string
          description: The brand id of the campaign, null if is a global campaign
          nullable: true
        platforms:
          type: array
          description: Platform select values where this campaign applies
          items:
            type: object
            properties:
              label:
                type: string
              value:
                type: string
          nullable: true
        stores:
          type: array
          description: >-
            Store ids associated with this campaign. These are descriptive
            associations and do not replace rule conditions.
          items:
            type: string
          nullable: true
        channels:
          type: array
          description: >-
            Channel ids associated with this campaign. These are descriptive
            associations and do not replace rule conditions.
          items:
            type: string
          nullable: true
        name:
          type: string
          description: The name of the campaign
        description:
          type: string
          description: The description of the campaign
        rules:
          type: string
          description: >-
            JSON string with the main/referrer campaign rules. Must contain at
            least one rule for every campaign type, including REFERRALS.
            referee_rules_json does not replace this field.
        attributes:
          description: The attributes of the campaign
          oneOf:
            - type: object
              description: >-
                The attributes of the campaign for BEHAVIOR campaigns. trigger
                must be a supported event type and privacy must be PRIVATE or
                PUBLIC.
              properties:
                trigger:
                  type: string
                  description: The trigger of the campaign
                  example: PURCHASE
                privacy:
                  type: string
                  description: The privacy of the campaign
                  enum:
                    - PRIVATE
                    - PUBLIC
            - type: object
              description: >-
                The attributes of the campaign for COUPONS campaigns. Coupon
                campaigns validate non-empty custom codes, generated-code
                quantity, coupon template format, positive redemption limits,
                and duplicate active/used coupon codes that match the template.
              properties:
                max_redemptions_per_code:
                  type: number
                  description: The maximum redemptions per code. Must be at least 1.
                  example: 1
                max_redemptions_per_code_per_customer:
                  type: number
                  description: >-
                    The maximum redemptions per code per customer. Must be at
                    least 1.
                  example: 1
                code_format:
                  type: object
                  description: >-
                    The format of generated coupon codes. Generated quantities
                    must stay within the template permutation count and under
                    the same safe limit enforced by the dashboard form. Custom
                    codes are checked for duplicates against active campaigns
                    and active redemptions when they match this template.
                  properties:
                    template:
                      type: string
                      description: The template that all coupon codes should follow
                      example: '********'
                    case_sensitive:
                      type: boolean
                      description: If the coupon code is case sensitive
                      example: false
                codes:
                  type: array
                  description: The codes of the campaign
                  items:
                    type: string
                    example: ABCD1234
            - type: object
              description: >-
                The attributes of the campaign for PUNCH_CARDS campaigns.
                cards_per_customer and punches_per_card must be positive unless
                unlimited_cards changes the dashboard form requirements. On
                update, if punches_per_card changes, rules must be rebuilt and
                cannot be the same rules currently stored on the campaign.
              properties:
                trigger:
                  type: string
                  example: PURCHASE
                privacy:
                  type: string
                  enum:
                    - PRIVATE
                    - PUBLIC
                unlimited_cards:
                  type: boolean
                cards_per_customer:
                  type: number
                punches_per_card:
                  type: number
            - type: object
              description: >-
                The attributes of the campaign for REFERRALS campaigns.
                Main/referrer rules are required in rules. referee_rules_json
                can add referee rules but cannot be the only reward definition.
              properties:
                trigger:
                  type: string
                  example: PURCHASE
                privacy:
                  type: string
                  enum:
                    - PRIVATE
                    - PUBLIC
                max_participations_per_customer:
                  type: number
                  description: Must be an integer between 1 and 100.
                stock:
                  type: number
                  description: Must be an integer between 1 and 100000.
                uses:
                  type: number
                  description: Must be an integer greater than or equal to 0.
        status:
          description: The persisted campaign status for create/update requests
          type: string
          enum:
            - ACTIVE
            - INACTIVE
        start_date:
          type: string
          description: >-
            The start date of the campaign. On create, and on updates for
            scheduled campaigns, it must be today or later and less than one
            year from now.
          format: date-time
        withoutEndDate:
          type: boolean
          description: >-
            When true, end_date must be omitted and the campaign is stored
            without an end date.
        end_date:
          type: string
          description: >-
            The end date of the campaign. Omit it when withoutEndDate is true.
            When provided, it must be after start_date and less than one year
            from start_date.
          format: date-time
          nullable: true
        funded_by:
          type: string
          description: Who is funding these campaign
          nullable: true
        budget:
          type: number
          description: The budget of the campaign
          example: 1000
        divide_budget_in:
          type: string
          enum:
            - daily
            - weekly
            - monthly
            - total
        labels:
          type: array
          description: Label select values
          items:
            type: object
            properties:
              label:
                type: string
              value:
                type: string
        metadata:
          type: string
          description: JSON object encoded as a string
        content:
          type: object
          description: >-
            Optional CMS content values for the campaign. Each key is a template
            field name and each value contains the field metadata, type, and
            value. Send an empty object when the campaign has no CMS content.
          additionalProperties: true
          example:
            Title:
              name: Title
              type: input
              value: Value of the title
            BannerImage:
              alt: Alternative description for the image
              href: Href link for the image
              name: Name of the image
              type: image
              value: https://URL_TO_IMAGE
            Description:
              name: Name of the description
              type: input
              value: Value of the description
        template_id:
          type: string
          description: >-
            Optional CMS template id used to structure the campaign content.
            Send null when no template is selected.
          format: uuid
          nullable: true
        quantity:
          type: number
          description: >-
            COUPONS only. Number of coupon codes to generate or keep. Must be
            positive and within the safe limit for generated codes.
        useCustomCodes:
          type: boolean
          description: >-
            COUPONS only. When true, customCodes is used instead of generated
            codes
        customCodes:
          type: string
          description: >-
            COUPONS only. Comma-separated custom coupon codes. Required to
            contain at least one non-empty code when useCustomCodes is true.
        confirm_changes:
          type: boolean
          description: >-
            COUPONS update only. Required as true when changing code format or
            quantity
        referee_rules_json:
          type: string
          description: >-
            REFERRALS only. JSON string with referee campaign rules. This is
            optional and does not replace the required main/referrer rules
            field.
    Campaign:
      type: object
      description: Campaign response. account_id, order, and created_at are not returned.
      additionalProperties: true
      properties:
        id:
          type: string
          description: The campaign internal unique identifier
          format: uuid
        name:
          type: string
          description: The name of the campaign
        status:
          description: The computed campaign status returned by the API
          type: string
          enum:
            - RUNNING
            - PAUSED
            - SCHEDULED
            - FINISHED
            - NOT FINISHED
        attributes:
          description: The attributes of the campaign
          type: object
          additionalProperties: true
        content:
          description: The CMS content values stored for the campaign
          type: object
          additionalProperties: true
          example:
            Title:
              name: Title
              type: input
              value: Value of the title
            BannerImage:
              alt: Alternative description for the image
              href: Href link for the image
              name: BannerImage
              type: image
              value: https://URL_TO_IMAGE
            Description:
              name: Name of the description
              type: input
              value: Value of the description
        template_id:
          description: >-
            The CMS template id associated with the campaign content, or null
            when there is no template.
          type: string
          format: uuid
          nullable: true
    Error:
      required:
        - error
        - details
      type: object
      properties:
        error:
          type: string
        details:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````