JavaScript
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);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)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)package main
import (
"context"
"fmt"
"github.com/moonbaseai/moonbase-sdk-go"
"github.com/moonbaseai/moonbase-sdk-go/option"
)
func main() {
client := moonbase.NewClient(
option.WithAPIKey("My API Key"),
)
programMessage, err := client.ProgramMessages.Send(context.TODO(), moonbase.ProgramMessageSendParams{
Person: moonbase.ProgramMessageSendParamsPerson{
Email: "person-206@example-206.com",
},
ProgramTemplateID: "1CLJt2v6ZuRbtwPhmQtzxa",
CustomVariables: map[string]any{
"coupon_code": "HOWDY",
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", programMessage.ID)
}
curl --request POST \
--url https://api.moonbase.ai/v0/program_messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"person": {
"email": "person-206@example-206.com"
},
"custom_variables": {
"coupon_code": "HOWDY"
},
"program_template_id": "1CLJt2v6ZuRbtwPhmQtzxa"
}
'{
"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"
}{
"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"
}
}
]
}{
"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\""
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "403",
"title": "Forbidden"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "409",
"title": "conflict",
"detail": "Program '1CLJt2v5aNd8G5SGzEaeVU' cannot be used to send messages because its status is 'paused'."
}
]
}{
"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"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "429",
"title": "Too Many Requests"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "500",
"title": "Internal Server Error"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "503",
"title": "Service Unavailable",
"detail": "The service is temporarily unavailable, please try again later."
}
]
}Program Messages
Send a Message
Sends a message using a program template.
POST
/
program_messages
JavaScript
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);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)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)package main
import (
"context"
"fmt"
"github.com/moonbaseai/moonbase-sdk-go"
"github.com/moonbaseai/moonbase-sdk-go/option"
)
func main() {
client := moonbase.NewClient(
option.WithAPIKey("My API Key"),
)
programMessage, err := client.ProgramMessages.Send(context.TODO(), moonbase.ProgramMessageSendParams{
Person: moonbase.ProgramMessageSendParamsPerson{
Email: "person-206@example-206.com",
},
ProgramTemplateID: "1CLJt2v6ZuRbtwPhmQtzxa",
CustomVariables: map[string]any{
"coupon_code": "HOWDY",
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", programMessage.ID)
}
curl --request POST \
--url https://api.moonbase.ai/v0/program_messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"person": {
"email": "person-206@example-206.com"
},
"custom_variables": {
"coupon_code": "HOWDY"
},
"program_template_id": "1CLJt2v6ZuRbtwPhmQtzxa"
}
'{
"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"
}{
"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"
}
}
]
}{
"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\""
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "403",
"title": "Forbidden"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "409",
"title": "conflict",
"detail": "Program '1CLJt2v5aNd8G5SGzEaeVU' cannot be used to send messages because its status is 'paused'."
}
]
}{
"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"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "429",
"title": "Too Many Requests"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "500",
"title": "Internal Server Error"
}
]
}{
"type": "errors",
"errors": [
{
"type": "error",
"status": "503",
"title": "Service Unavailable",
"detail": "The service is temporarily unavailable, please try again later."
}
]
}Authorizations
Your Moonbase API key.
Body
application/json
The ProgramMessage to be sent.
Parameters for sending a ProgramMessage.
Response
Message accepted.
Represents a single message sent as part of a Program.
String representing the object’s type. Always program_message for this object.
Allowed value:
"program_message"Unique identifier for the object.
The ProgramTemplate used to generate this message.
Show child attributes
Show child attributes
Time at which the message was created and enqueued for sending, as an ISO 8601 timestamp in UTC.
Time at which the object was last updated, as an ISO 8601 timestamp in UTC.
⌘I

