# Stack chat messages and creator notes (/indexify-api-documentation/stack-chat/chat)

```json
[
  {
    "path": "/api/chat.php",
    "method": "post",
    "tags": [
      "Chat"
    ],
    "summary": "Stack chat messages and creator notes",
    "description": "Manage community messages and creator notes on a stack's chat. The `action` query parameter selects the sub-operation.\n",
    "security": [
      {},
      {
        "ApiKeyAuth": []
      }
    ],
    "parameters": [
      {
        "name": "action",
        "in": "query",
        "required": true,
        "schema": {
          "type": "string",
          "enum": [
            "addMessage",
            "getAll",
            "togglePin"
          ]
        }
      }
    ],
    "requestBody": {
      "required": true,
      "content": {
        "application/json": {
          "schema": {
            "oneOf": [
              {
                "title": "addMessage",
                "type": "object",
                "required": [
                  "stack_id",
                  "message"
                ],
                "properties": {
                  "stack_id": {
                    "type": "integer",
                    "description": "Stack whose chat to post to."
                  },
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 1000,
                    "description": "Message body (1-1000 characters). HTML tags are stripped."
                  },
                  "message_type": {
                    "type": "string",
                    "enum": [
                      "community",
                      "creator_notes"
                    ],
                    "default": "community",
                    "description": "Message type. `creator_notes` is restricted to the stack creator.\n"
                  },
                  "pinned": {
                    "type": "boolean",
                    "default": false,
                    "description": "Pin this message (creator_notes only). Unpins any previously pinned note."
                  }
                }
              },
              {
                "title": "getAll",
                "type": "object",
                "required": [
                  "stack_id"
                ],
                "properties": {
                  "stack_id": {
                    "type": "integer"
                  },
                  "message_type": {
                    "type": "string",
                    "enum": [
                      "community",
                      "creator_notes"
                    ],
                    "default": "community"
                  },
                  "page": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 1
                  },
                  "limit": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "default": 50
                  }
                }
              },
              {
                "title": "togglePin",
                "type": "object",
                "required": [
                  "message_id"
                ],
                "properties": {
                  "message_id": {
                    "type": "integer",
                    "description": "ID of the creator note to pin or unpin."
                  }
                }
              }
            ]
          }
        }
      }
    },
    "responses": {
      "200": {
        "description": "Successful response. Shape varies by action.",
        "content": {
          "application/json": {
            "schema": {
              "oneOf": [
                {
                  "title": "AddMessageResponse",
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "examples": [
                        true
                      ]
                    },
                    "message": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "integer"
                        },
                        "stack_id": {
                          "type": "integer"
                        },
                        "messages": {
                          "type": "string",
                          "description": "The message content."
                        },
                        "message_type": {
                          "type": "string",
                          "enum": [
                            "community",
                            "creator_notes"
                          ]
                        },
                        "pinned": {
                          "type": "boolean"
                        },
                        "created_at": {
                          "type": "integer",
                          "description": "Unix timestamp."
                        },
                        "user": {
                          "type": "object",
                          "properties": {
                            "id": {
                              "type": "integer"
                            },
                            "username": {
                              "type": "string"
                            },
                            "avatar": {
                              "type": [
                                "string",
                                "null"
                              ]
                            }
                          }
                        }
                      }
                    }
                  }
                },
                {
                  "title": "GetAllResponse",
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "examples": [
                        true
                      ]
                    },
                    "messages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ChatMessage"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "page": {
                          "type": "integer"
                        },
                        "limit": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        },
                        "total_pages": {
                          "type": "integer"
                        },
                        "has_next": {
                          "type": "boolean"
                        },
                        "has_prev": {
                          "type": "boolean"
                        }
                      }
                    },
                    "message_type_supported": {
                      "type": "boolean"
                    },
                    "pinned_notes": {
                      "type": [
                        "array",
                        "null"
                      ],
                      "description": "Only present when message_type is creator_notes. Contains pinned creator notes outside pagination.\n",
                      "items": {
                        "$ref": "#/components/schemas/ChatMessage"
                      }
                    }
                  }
                },
                {
                  "title": "TogglePinResponse",
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "examples": [
                        true
                      ]
                    },
                    "message_id": {
                      "type": "integer"
                    },
                    "pinned": {
                      "type": "boolean"
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "400": {
        "description": "Validation error (missing fields, message too long/short, etc.).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "403": {
        "description": "Forbidden (not the stack creator for creator_notes / togglePin).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "404": {
        "description": "Chat or message not found.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "500": {
        "description": "Internal server error.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
]
```