Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sam-shervin/space7/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Sends a new message to the specified space. Messages can contain text content, a media attachment, or both. At least one of content or media must be provided.

Endpoint

POST /api/messages/:spaceId
Requires authentication

Request

Path parameters

spaceId
string
required
The unique identifier of the space to post the message to.

Body parameters

The request body must be sent as multipart/form-data.
content
string
The text content of the message. Required if no media is attached.
media
file
A media file to attach to the message. Accepted types: image, video, audio. Required if no content is provided.
media_type
string
The type of media being uploaded. Accepted values: "image", "video", "audio". Required when media is provided.
At least one of content or media must be included in the request. Sending a request with neither will result in an error.

Response

Returns the created Message object.
message_id
string
Unique identifier for the newly created message.
space_id
string
Identifier of the space the message was posted to.
sender_id
string
Identifier of the user who sent the message.
content
string
Text content of the message.
media_url
string | null
URL of the uploaded media file, or null if no media was attached.
media_type
image | video | audio | null
Type of the attached media, or null if no media was attached.
word_count
number
Number of words in the message content.
sender
SpaceCreator
Profile information of the message sender.
likes
MessageLike[]
Array of likes on the message. Will be empty for a newly created message.
appreciation_count
number
Total number of appreciations. Will be 0 for a newly created message.
created_at
string
ISO 8601 timestamp of when the message was created.

Example

TypeScript
import { fetchWithAuth } from "./fetchWithAuth";

const sendMessage = async (
  spaceId: string,
  payload: {
    content?: string;
    media?: { uri: string; name?: string; type?: string } | null;
    media_type?: "image" | "video" | "audio";
  },
) => {
  if (!payload.content?.trim() && !payload.media) {
    throw new Error("Message must have text or media");
  }

  const formData = new FormData();

  if (payload.content?.trim()) {
    formData.append("content", payload.content.trim());
  }

  if (payload.media) {
    formData.append("media", {
      uri: payload.media.uri,
      name: payload.media.name ?? "upload",
      type: payload.media.type ?? "application/octet-stream",
    } as never);
  }

  if (payload.media_type) {
    formData.append("media_type", payload.media_type);
  }

  const res = await fetchWithAuth(`/api/messages/${spaceId}`, {
    method: "POST",
    body: formData,
  });

  const data = await res.json();

  if (!res.ok) {
    throw new Error(data.error || "Failed to send message");
  }

  return data; // Message
};

Build docs developers (and LLMs) love