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

# Send a Message

> Sends a message using a program template.



## OpenAPI

````yaml POST /program_messages
openapi: 3.1.0
info:
  title: Moonbase REST API
  version: v0
servers:
  - url: https://api.moonbase.ai/v0
security:
  - bearer: []
tags:
  - name: Inboxes
    description: Manage your inboxes, conversations, and messages
  - name: Collections
    description: Manage your collections and items
  - name: Marketing
    description: Manage your marketing campaigns and forms
  - name: Activities
    description: View activities and capture calls
  - name: Library
    description: Manage your meetings, files, and notes
paths:
  /program_messages:
    post:
      tags:
        - Marketing
      summary: Send a message
      description: Sends a message using a program template.
      parameters: []
      requestBody:
        description: The `ProgramMessage` to be sent.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProgramMessageSendParams'
            examples:
              Send a message with custom variables:
                summary: Send a message with custom variables
                value:
                  person:
                    email: person-206@example-206.com
                  custom_variables:
                    coupon_code: HOWDY
                  program_template_id: 1CLJt2v6ZuRbtwPhmQtzxa
      responses:
        '202':
          description: Message accepted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProgramMessage'
              examples:
                Send a message with custom variables:
                  summary: Send a message with custom variables
                  value:
                    id: 1CLJt2v8oMEB5Nnv24cJ1Z
                    type: program_message
                    program_template:
                      id: 1CLJt2v6ZuRbtwPhmQtzxa
                      type: program_template
                      subject: Test Subject to {{ person.name }}
                      body:
                        markdown: Your coupon code is [TEST]
                      created_at: '2025-02-17T16:00:00.000Z'
                      updated_at: '2025-02-17T16:00:00.000Z'
                    created_at: '2025-02-17T16:00:00.000Z'
                    updated_at: '2025-02-17T16:00:00.000Z'
        '400':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Unknown custom variables:
                  summary: Unknown custom variables
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '400'
                        title: Bad Request
                        detail: >-
                          Your request includes custom variables, but your
                          template does not use any custom variables.
                        source:
                          pointer: /custom_attributes
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '401'
                        title: Unauthorized
                        detail: >-
                          Invalid or missing API key or JWT. You should provide
                          your Moonbase API Key or JWT in the authorization
                          header, in the format: "Authorization: Bearer
                          MOONBASE_API_KEY"
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '403'
                        title: Forbidden
        '409':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Program paused:
                  summary: Program paused
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '409'
                        title: conflict
                        detail: >-
                          Program '1CLJt2v5aNd8G5SGzEaeVU' cannot be used to
                          send messages because its status is 'paused'.
        '422':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Drafts can't be sent to others:
                  summary: Drafts can't be sent to others
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '422'
                        title: unprocessable_entity
                        detail: >-
                          Draft programs may only be sent to emails that are
                          owned by your Moonbase account
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '429'
                        title: Too Many Requests
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '500'
                        title: Internal Server Error
        '503':
          description: Service Unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Errors'
              examples:
                Default:
                  summary: Default
                  value:
                    type: errors
                    errors:
                      - type: error
                        status: '503'
                        title: Service Unavailable
                        detail: >-
                          The service is temporarily unavailable, please try
                          again later.
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Moonbase from '@moonbaseai/sdk';

            const client = new Moonbase({
              apiKey: process.env['MOONBASE_API_KEY'], // This is the default and can be omitted
            });

            const programMessage = await client.programMessages.send({
              person: { email: 'person-206@example-206.com' },
              program_template_id: '1CLJt2v6ZuRbtwPhmQtzxa',
              custom_variables: { coupon_code: 'HOWDY' },
            });

            console.log(programMessage.id);
        - lang: Python
          source: |-
            import os
            from moonbase import Moonbase

            client = Moonbase(
                api_key=os.environ.get("MOONBASE_API_KEY"),  # This is the default and can be omitted
            )
            program_message = client.program_messages.send(
                person={
                    "email": "person-206@example-206.com"
                },
                program_template_id="1CLJt2v6ZuRbtwPhmQtzxa",
                custom_variables={
                    "coupon_code": "HOWDY"
                },
            )
            print(program_message.id)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/moonbaseai/moonbase-sdk-go\"\n\t\"github.com/moonbaseai/moonbase-sdk-go/option\"\n)\n\nfunc main() {\n\tclient := moonbase.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tprogramMessage, err := client.ProgramMessages.Send(context.TODO(), moonbase.ProgramMessageSendParams{\n\t\tPerson: moonbase.ProgramMessageSendParamsPerson{\n\t\t\tEmail: \"person-206@example-206.com\",\n\t\t},\n\t\tProgramTemplateID: \"1CLJt2v6ZuRbtwPhmQtzxa\",\n\t\tCustomVariables: map[string]any{\n\t\t\t\"coupon_code\": \"HOWDY\",\n\t\t},\n\t})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", programMessage.ID)\n}\n"
        - lang: Ruby
          source: |-
            require "moonbase"

            moonbase = Moonbase::Client.new(api_key: "My API Key")

            program_message = moonbase.program_messages.send_(
              person: {email: "person-206@example-206.com"},
              program_template_id: "1CLJt2v6ZuRbtwPhmQtzxa"
            )

            puts(program_message)
components:
  schemas:
    ProgramMessageSendParams:
      title: ProgramMessageSendParams
      description: Parameters for sending a `ProgramMessage`.
      type: object
      properties:
        person:
          description: The person to send the message to.
          type: object
          properties:
            email:
              type: string
              format: email
          required:
            - email
        custom_variables:
          description: >-
            Any custom Liquid variables to be interpolated into the message
            template.
          type: object
          additionalProperties: true
        program_template_id:
          description: The ID of the `ProgramTemplate` to use for sending the message.
          type: string
      required:
        - person
        - program_template_id
    ProgramMessage:
      title: ProgramMessage
      description: Represents a single message sent as part of a `Program`.
      type: object
      properties:
        type:
          description: >-
            String representing the object’s type. Always `program_message` for
            this object.
          type: string
          const: program_message
        id:
          description: Unique identifier for the object.
          type: string
        program_template:
          $ref: '#/components/schemas/ProgramTemplate'
          description: The `ProgramTemplate` used to generate this message.
        created_at:
          description: >-
            Time at which the message was created and enqueued for sending, as
            an ISO 8601 timestamp in UTC.
          type: string
          format: date-time
        updated_at:
          description: >-
            Time at which the object was last updated, as an ISO 8601 timestamp
            in UTC.
          type: string
          format: date-time
      required:
        - program_template
        - type
        - id
        - created_at
        - updated_at
    Errors:
      title: Errors
      description: >-
        The Errors object is a container that holds multiple Error objects when
        an API request encounters several validation or processing issues. This
        allows the API to return comprehensive feedback about all problems
        encountered in a single response.
      type: object
      properties:
        type:
          type: string
          const: errors
        errors:
          description: A list of `Error` objects.
          type: array
          items:
            $ref: '#/components/schemas/Error'
      required:
        - type
    ProgramTemplate:
      title: ProgramTemplate
      description: >-
        The ProgramTemplate object defines the content of a message sent by a
        `Program`, including support for Liquid templating.
      type: object
      properties:
        type:
          description: >-
            String representing the object’s type. Always `program_template` for
            this object.
          type: string
          const: program_template
        id:
          description: Unique identifier for the object.
          type: string
        subject:
          description: The subject line of the email, which can include Liquid variables.
          type: string
        body:
          $ref: '#/components/schemas/FormattedText'
          description: The body content of the email, which can include Liquid variables.
        program:
          $ref: '#/components/schemas/Program'
          description: >
            The `Program` that uses this template.


            **Note:** Only present when requested using the `include` query
            parameter.
        created_at:
          description: >-
            Time at which the object was created, as an ISO 8601 timestamp in
            UTC.
          type: string
          format: date-time
        updated_at:
          description: >-
            Time at which the object was last updated, as an ISO 8601 timestamp
            in UTC.
          type: string
          format: date-time
      required:
        - subject
        - type
        - id
        - body
        - created_at
        - updated_at
    Error:
      title: Error
      description: >-
        The Error object represents a single error that occurred during API
        request processing. It provides detailed information about what went
        wrong, including a unique identifier, status code, and human-readable
        descriptions to help developers understand and resolve the issue.
      type: object
      properties:
        type:
          type: string
          const: error
        id:
          description: A unique identifier for this specific error instance.
          type: string
        status:
          description: The HTTP status code for this problem, as a string.
          type: string
        code:
          description: An application-specific error code string.
          type: string
        title:
          description: A short, human-readable summary of the problem.
          type: string
        detail:
          description: A human-readable explanation of this specific error.
          type: string
        source:
          $ref: '#/components/schemas/ErrorSource'
          description: >-
            An object containing more specific information about the part of the
            request that caused the error.
        meta:
          type: object
          additionalProperties: true
      required:
        - type
    FormattedText:
      title: FormattedText
      description: >-
        Structured content that can be rendered in multiple formats, currently
        supporting Markdown.
      type: object
      properties:
        markdown:
          description: The content formatted as Markdown text.
          type: string
      required: []
    Program:
      title: Program
      description: >-
        The Program object represents an email campaign. It defines the sending
        behavior and tracks engagement metrics.
      type: object
      properties:
        type:
          description: >-
            String representing the object’s type. Always `program` for this
            object.
          type: string
          const: program
        id:
          description: Unique identifier for the object.
          type: string
        display_name:
          description: The user-facing name of the program.
          type: string
        status:
          description: >-
            The current status of the program. Can be `draft`, `published`,
            `paused`, or `archived`.
          type: string
          enum:
            - draft
            - published
            - paused
            - archived
        trigger:
          description: >-
            The sending trigger for the program. Can be `api` for transactional
            sends or `broadcast` for scheduled sends.
          type: string
          enum:
            - api
            - broadcast
        scheduled_at:
          description: >-
            For `broadcast` programs, the time the program is scheduled to send,
            as an ISO 8601 timestamp in UTC.
          type: string
          format: date-time
        track_opens:
          description: '`true` if email opens are tracked for this program.'
          type: boolean
        track_clicks:
          description: '`true` if link clicks are tracked for this program.'
          type: boolean
        activity_metrics:
          $ref: '#/components/schemas/ProgramActivityMetrics'
          description: >
            A `ProgramActivityMetrics` object summarizing engagement for this
            program.


            **Note:** Only present when requested using the `include` query
            parameter.
        program_template:
          $ref: '#/components/schemas/ProgramTemplate'
          description: >
            The `ProgramTemplate` used for messages in this program.


            **Note:** Only present when requested using the `include` query
            parameter.
        created_at:
          description: >-
            Time at which the object was created, as an ISO 8601 timestamp in
            UTC.
          type: string
          format: date-time
        updated_at:
          description: >-
            Time at which the object was last updated, as an ISO 8601 timestamp
            in UTC.
          type: string
          format: date-time
      required:
        - trigger
        - type
        - id
        - status
        - track_opens
        - track_clicks
        - created_at
        - updated_at
    ErrorSource:
      title: ErrorSource
      description: >-
        The ErrorSource object provides additional context about the specific
        part of an API request that caused an error. It can point to either a
        field in the request document or a query parameter that contains invalid
        data.
      type: object
      properties:
        pointer:
          description: >-
            A JSON Pointer [RFC6901] to the associated entity in the request
            document.
          type: string
        parameter:
          description: A string indicating which URI query parameter caused the error.
          type: string
      required: []
    ProgramActivityMetrics:
      title: ProgramActivityMetrics
      description: >-
        The ProgramActivityMetrics object provides a summary of engagement and
        delivery statistics for a marketing program.
      type: object
      properties:
        bounced:
          description: The number of emails that could not be delivered.
          type: integer
        clicked:
          description: The number of recipients who clicked at least one link.
          type: integer
        complained:
          description: The number of recipients who marked the email as spam.
          type: integer
        failed:
          description: The number of emails that failed to send due to a technical issue.
          type: integer
        opened:
          description: The number of recipients who opened the email.
          type: integer
        sent:
          description: The total number of emails successfully sent.
          type: integer
        shielded:
          description: The number of emails blocked by delivery protection rules.
          type: integer
        unsubscribed:
          description: The number of recipients who unsubscribed.
          type: integer
      required:
        - bounced
        - clicked
        - complained
        - failed
        - opened
        - sent
        - shielded
        - unsubscribed
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: Your Moonbase API key.

````