Post Announcement API

This endpoint allows you to create and publish a new announcement.

Endpoint

POST /api/announcement

Authentication

The API uses an API key to authenticate access. You may insert the provided API key in your requests header Authorization like the following:

Authorization: Bearer {API key}

Replace YOUR_API_KEY with the actual API key provided to you.

Headers

  • Content-Type: application/json
  • Accept: application/json

Request Body

Send a JSON object with the following properties:

PropertyTypeRequiredDescription
user_idintegerYesThe ID of the user creating the announcement.
contentstringYesThe main content of the announcement. Can include HTML, which will be sanitized.
subscriptionsarray of integersYesAn array of subscription IDs to which this announcement will be sent.
titlestringNoThe title of the announcement. If not provided, one will be generated from the content.
announcement_typeintegerNoThe ID of the announcement type.
send_emailbooleanNoWhether to send this announcement via email. Defaults to false if not provided.
send_smsbooleanNoWhether to send this announcement via SMS. Defaults to false if not provided.
send_pushbooleanNoWhether to send this announcement as a push notification. Defaults to false if not provided.
suppressed_subscriptionsarray of integersNoAn array of subscription IDs that should not receive this announcement.
hiddenbooleanNoWhether this announcement should be hidden. Defaults to false if not provided.

Example Request

Copy

{
"user_id": 1,
"content": "<p>We are excited to announce our new product launch!</p>",
"subscriptions": [1, 2, 3],
"title": "New Product Launch",
"announcement_type": 1,
"send_email": true,
"send_push": true,
"send_sms": false,
"suppressed_subscriptions": [4],
"hidden": false
}

Response

Success Response

Code: 200 OK

Content example:Copy

{
  "message": "Announcement created and published successfully",
  "announcement": {
    "id": 123,
    "content": "<p>We are excited to announce our new product launch!</p>",
    "title": "New Product Launch",
    "type": {
      "id": 1,
      "label": "Product Update",
      "label_color": "#00ff00"
    },
    "subscriptions": [
      {"id": 1, "name": "Premium Subscribers"},
      {"id": 2, "name": "Regular Subscribers"},
      {"id": 3, "name": "Beta Testers"}
    ],
    "email": true,
    "sms": false,
    "push": true,
    "published": true,
    "hidden": false,
    "created_at": "2023-06-15T10:00:00Z",
    "updated_at": "2023-06-15T10:00:00Z"
  }
}

Error Responses

Code: 422 Unprocessable Entity

Content example:Copy

{
  "errors": {
    "content": [
      "The content field is required."
    ],
    "subscriptions": [
      "The subscriptions field is required."
    ]
  }
}

Code: 401 Unauthorized

Content example:Copy

{
  "message": "Unauthenticated."
}

Notes

  • The content field will be sanitized to remove potentially malicious HTML.
  • Make sure all subscription IDs provided in subscriptions and suppressed_subscriptions exist in the system.
  • The announcement will be immediately published upon creation.

Objective Learning Management System (LMS) allows administrators to create and manage online courses for members. This guide walks through the