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

# Notes API

> Create, read, update, and delete personal notes

# Notes API

## Create Note

<Card title="POST /notes-create" icon="plus">
  Create a new personal note
</Card>

**Base URL**: `https://rzqklwfhwqmviintncqh.supabase.co/functions/v1`

### Request

<ParamField header="Authorization" type="string" required>
  Bearer token from authentication
</ParamField>

<ParamField header="Content-Type" type="string" required>
  application/json
</ParamField>

<ParamField body="title" type="string">
  Note title (optional, but title or content required)
</ParamField>

<ParamField body="content" type="string">
  Note content (optional, but title or content required)
</ParamField>

<ParamField body="status" type="string" default="DRAFT">
  Note status: DRAFT or PUBLISHED
</ParamField>

### Response

<ResponseField name="message" type="string">
  Success message
</ResponseField>

<ResponseField name="success" type="boolean">
  Request success indicator
</ResponseField>

<ResponseField name="data" type="object">
  <Expandable title="data">
    <ResponseField name="id" type="string">Unique note identifier</ResponseField>
    <ResponseField name="title" type="string">Note title</ResponseField>
    <ResponseField name="content" type="string">Note content</ResponseField>
    <ResponseField name="status" type="string">Note status</ResponseField>
    <ResponseField name="createdBy" type="string">User ID who created the note</ResponseField>
    <ResponseField name="createdAt" type="string">Creation timestamp</ResponseField>
    <ResponseField name="updatedAt" type="string">Last update timestamp</ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/notes-create \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
    -H "Content-Type: application/json" \
    -d '{
      "title": "My Daily Reflection",
      "content": "Today I learned about the importance of gratitude in my spiritual journey.",
      "status": "DRAFT"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/notes-create', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${accessToken}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      title: 'My Daily Reflection',
      content: 'Today I learned about the importance of gratitude in my spiritual journey.',
      status: 'DRAFT'
    })
  });

  const note = await response.json();
  ```

  ```dart Flutter theme={null}
  final response = await http.post(
    Uri.parse('https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/notes-create'),
    headers: {
      'Authorization': 'Bearer $accessToken',
      'Content-Type': 'application/json',
    },
    body: jsonEncode({
      'title': 'My Daily Reflection',
      'content': 'Today I learned about the importance of gratitude in my spiritual journey.',
      'status': 'DRAFT',
    }),
  );

  final note = jsonDecode(response.body);
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "message": "Note created successfully",
    "data": {
      "id": "42f688be-1751-4935-8572-78039910b6fe",
      "title": "My Daily Reflection",
      "content": "Today I learned about the importance of gratitude in my spiritual journey.",
      "status": "DRAFT",
      "createdBy": "f9cc094c-ba9c-4a0a-82b9-e40d589e97db",
      "createdAt": "2025-10-14T07:19:33.294Z",
      "updatedAt": "2025-10-14T07:19:33.294Z"
    },
    "success": true
  }
  ```

  ```json Error Response theme={null}
  {
    "error": "At least title or content is required",
    "success": false
  }
  ```
</ResponseExample>

***

## Fetch Notes

<Card title="GET /notes-fetch" icon="list">
  Retrieve user's personal notes with pagination
</Card>

### Request

<ParamField header="Authorization" type="string" required>
  Bearer token from authentication
</ParamField>

<ParamField query="limit" type="number" default="10">
  Maximum number of notes to return (1-100)
</ParamField>

<ParamField query="offset" type="number" default="0">
  Number of notes to skip for pagination
</ParamField>

### Response

<ResponseField name="message" type="string">
  Success message
</ResponseField>

<ResponseField name="success" type="boolean">
  Request success indicator
</ResponseField>

<ResponseField name="data" type="object">
  <Expandable title="data">
    <ResponseField name="notes" type="array">
      Array of note objects (same structure as create response)
    </ResponseField>

    <ResponseField name="pagination" type="object">
      <Expandable title="pagination">
        <ResponseField name="total" type="number">Total number of user's notes</ResponseField>
        <ResponseField name="limit" type="number">Requested limit</ResponseField>
        <ResponseField name="offset" type="number">Current offset</ResponseField>
        <ResponseField name="hasMore" type="boolean">Whether more notes are available</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="userId" type="string">ID of the authenticated user</ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET "https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/notes-fetch?limit=5&offset=0" \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/notes-fetch?limit=5', {
    headers: {
      'Authorization': `Bearer ${accessToken}`
    }
  });

  const data = await response.json();
  const notes = data.data.notes;
  ```

  ```dart Flutter theme={null}
  final response = await http.get(
    Uri.parse('https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/notes-fetch?limit=5'),
    headers: {
      'Authorization': 'Bearer $accessToken',
    },
  );

  final data = jsonDecode(response.body);
  final notes = data['data']['notes'];
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response theme={null}
  {
    "message": "Notes fetched successfully",
    "data": {
      "notes": [
        {
          "id": "f1e7a5ad-d405-46b3-a776-90da44252662",
          "title": "Morning Prayer",
          "content": "Grateful for this new day and the opportunities it brings.",
          "status": "DRAFT",
          "createdBy": "f9cc094c-ba9c-4a0a-82b9-e40d589e97db",
          "createdAt": "2025-10-14T09:33:33.348Z",
          "updatedAt": "2025-10-14T09:33:33.348Z"
        },
        {
          "id": "15206eac-f9b0-4bb7-9ca1-be9dc254634b",
          "title": "Bible Study Notes",
          "content": "Key insights from today's reading in Psalms.",
          "status": "PUBLISHED",
          "createdBy": "f9cc094c-ba9c-4a0a-82b9-e40d589e97db",
          "createdAt": "2025-10-14T08:31:27.705Z",
          "updatedAt": "2025-10-14T08:31:27.705Z"
        }
      ],
      "pagination": {
        "total": 2,
        "limit": 5,
        "offset": 0,
        "hasMore": false
      },
      "userId": "f9cc094c-ba9c-4a0a-82b9-e40d589e97db"
    },
    "success": true
  }
  ```
</ResponseExample>

***

## Update Note

<Card title="POST /notes-save" icon="pencil">
  Update an existing note
</Card>

**Base URL**: `https://rzqklwfhwqmviintncqh.supabase.co/functions/v1`

### Request

<ParamField body="id" type="string" required>
  Note ID to update
</ParamField>

<ParamField header="Authorization" type="string" required>
  Bearer token from authentication
</ParamField>

<ParamField header="Content-Type" type="string" required>
  application/json
</ParamField>

<ParamField body="title" type="string">
  Updated note title
</ParamField>

<ParamField body="content" type="string">
  Updated note content
</ParamField>

<ParamField body="status" type="string">
  Updated note status (DRAFT or PUBLISHED)
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/notes-save \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
    -H "Content-Type: application/json" \
    -d '{
      "id": "42f688be-1751-4935-8572-78039910b6fe",
      "title": "Updated Reflection",
      "content": "Updated content with new insights."
    }'
  ```
</RequestExample>

***

## Delete Note

<Card title="DELETE /notes-delete?id=:id" icon="trash">
  Delete a note
</Card>

**Base URL**: `https://rzqklwfhwqmviintncqh.supabase.co/functions/v1`

### Request

<ParamField query="id" type="string" required>
  Note ID to delete
</ParamField>

<ParamField header="Authorization" type="string" required>
  Bearer token from authentication
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X DELETE "https://rzqklwfhwqmviintncqh.supabase.co/functions/v1/notes-delete?id=42f688be-1751-4935-8572-78039910b6fe" \
    -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  ```
</RequestExample>

## Privacy & Security

<Warning>
  **Privacy Protection**: All notes endpoints automatically filter results to show only notes belonging to the authenticated user. Users cannot access other users' notes.
</Warning>

### Security Features

* **JWT Validation**: All requests require valid authentication tokens
* **User Isolation**: Notes are filtered by the authenticated user's ID extracted from JWT
* **Supabase Storage**: Notes are stored directly in the Supabase database
* **Input Validation**: All input is validated and sanitized

### Data Flow

```mermaid theme={null}
graph LR
    A[Mobile App] --> B[Edge Function]
    B --> C[JWT Validation]
    C --> D[Extract User ID]
    D --> E[Filter by User]
    E --> F[Database Query]
    F --> G[Return User Notes Only]
```

## Error Codes

| Status Code | Error                 | Description                              |
| ----------- | --------------------- | ---------------------------------------- |
| 400         | Bad Request           | Missing required fields or invalid data  |
| 401         | Unauthorized          | Invalid or missing authentication token  |
| 404         | Not Found             | Note not found or doesn't belong to user |
| 500         | Internal Server Error | Server error occurred                    |

<Note>
  Supabase is the source of truth for notes.
</Note>
