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

# Query Funds, Documents, and Portfolio Data

> Learn how to list funds, retrieve fund details with documents and sections, embed portfolio data, and access source PDFs through the MKK API.

The MKK Structured Data API organizes financial data around funds and the documents they publish. You can retrieve a flat list of all available funds, drill into a single fund's detail to see its associated documents and sections, embed portfolio entries directly in the fund response, and stream the original PDF source for any document. This guide walks you through each of these operations in sequence.

<Steps>
  <Step title="List all funds">
    Call `GET /funds` to retrieve every fund available in the dataset. No parameters are required.

    ```bash theme={null}
    curl https://mkk-roan.vercel.app/api/funds
    ```

    The response returns a `funds` array, each object containing a `fund_code`, `fund_title`, document counts, and the period range covered.

    ```json theme={null}
    {
      "funds": [
        {
          "id": "1",
          "fund_code": "OJB",
          "fund_title": "OJB Değişken Fon",
          "document_count": 48,
          "period_count": 16,
          "line_item_count": 94,
          "first_period": "2019-Q1",
          "last_period": "2023-Q4"
        },
        {
          "id": "2",
          "fund_code": "AKB",
          "fund_title": "AKB Bono Fonu",
          "document_count": 36,
          "period_count": 12,
          "line_item_count": 78,
          "first_period": "2020-Q1",
          "last_period": "2023-Q4"
        }
      ]
    }
    ```
  </Step>

  <Step title="Get fund detail with documents and sections">
    Call `GET /funds/{fundId}` using the fund code (e.g., `OJB`) to retrieve full detail for a single fund, including its linked documents, sections, and line items.

    ```bash theme={null}
    curl https://mkk-roan.vercel.app/api/funds/OJB
    ```

    The response includes nested `documents`, `sections`, and `line_items` arrays alongside the fund-level fields.

    ```json theme={null}
    {
      "id": "1",
      "fund_code": "OJB",
      "fund_title": "OJB Değişken Fon",
      "document_count": 48,
      "period_count": 16,
      "line_item_count": 94,
      "first_period": "2019-Q1",
      "last_period": "2023-Q4",
      "portfolio_entry_count": 14320,
      "documents": [
        {
          "id": 42,
          "disclosure_index": "FCH2023Q4",
          "fund_code": "OJB",
          "period": "2023-Q4",
          "document_type": "quarterly",
          "report_date": "2024-01-15",
          "line_item_value_count": 94,
          "portfolio_entry_count": 312,
          "portfolio_row_count": 318
        }
      ],
      "sections": [],
      "line_items": [],
      "portfolio_sections": ["Devlet İç Borçlanma Senetleri", "Özel Sektör Tahvilleri"],
      "portfolio_limit": 500,
      "portfolio_offset": 0,
      "portfolio_entries": []
    }
    ```
  </Step>

  <Step title="Embed portfolio entries in the fund response">
    Add `include_portfolio=true` to embed portfolio entries directly inside the fund detail response. Use `portfolio_limit` and `portfolio_offset` to paginate the embedded list.

    ```bash theme={null}
    curl "https://mkk-roan.vercel.app/api/funds/OJB?include_portfolio=true&portfolio_limit=100"
    ```

    The fund object will contain a `portfolio_entries` array. The `portfolio_entry_count` at the top level tells you the full count of entries available.

    <Note>
      `portfolio_limit` and `portfolio_offset` only affect the embedded `portfolio_entries` array. They do not paginate the fund's document or line item lists.
    </Note>
  </Step>

  <Step title="Include line item values in fund detail">
    Add `include_values=true` to embed structured line item values — such as net asset values and expense ratios — directly in the fund detail response. Each line item in the `line_items` array will include a nested `values` array.

    ```bash theme={null}
    curl "https://mkk-roan.vercel.app/api/funds/OJB?include_values=true"
    ```
  </Step>

  <Step title="Find documents for a fund by period">
    Use `GET /documents` with the `fund_code` and `period` parameters to retrieve all documents published by a specific fund within a given time range.

    ```bash theme={null}
    curl "https://mkk-roan.vercel.app/api/documents?fund_code=OJB&period=2023"
    ```

    The `period` parameter performs a prefix match, so `2023` returns all documents for that year across any period format. You can narrow it further with values like `2023-Q1`.

    ```json theme={null}
    {
      "total": 4,
      "limit": 50,
      "offset": 0,
      "documents": [
        {
          "id": 42,
          "disclosure_index": "FCH2023Q4",
          "fund_code": "OJB",
          "fund_title": "OJB Değişken Fon",
          "period": "2023-Q4",
          "document_type": "quarterly",
          "report_date": "2024-01-15",
          "line_item_value_count": 94,
          "portfolio_entry_count": 312,
          "portfolio_row_count": 318
        },
        {
          "id": 38,
          "disclosure_index": "FCH2023Q3",
          "fund_code": "OJB",
          "fund_title": "OJB Değişken Fon",
          "period": "2023-Q3",
          "document_type": "quarterly",
          "report_date": "2023-10-15",
          "line_item_value_count": 91,
          "portfolio_entry_count": 298,
          "portfolio_row_count": 304
        }
      ]
    }
    ```
  </Step>

  <Step title="Get a document with raw extracted data">
    Call `GET /documents/{docId}` with `include_raw=true` to retrieve the full document detail along with raw extracted text and table structures. Accepted truthy values for this parameter are `1`, `true`, `yes`, and `on`.

    ```bash theme={null}
    curl "https://mkk-roan.vercel.app/api/documents/42?include_raw=true"
    ```

    The response includes all standard document fields plus `raw_text` (full extracted text) and `tables` (raw table structures parsed from each page). Omit `include_raw` for smaller responses when you only need structured data.
  </Step>

  <Step title="Stream the source PDF">
    Call `GET /documents/{docId}/pdf` to stream the original PDF file as submitted to the MKK disclosure system. The response uses `Content-Type: application/pdf`.

    ```bash theme={null}
    curl https://mkk-roan.vercel.app/api/documents/42/pdf -o report.pdf
    ```

    Use the `-o` flag to save the file locally. You can open the downloaded file in any PDF viewer to inspect the source document.

    <Tip>
      If you want to verify a parsed value against the source, streaming the PDF and cross-referencing it with `include_raw=true` data is the most reliable approach.
    </Tip>
  </Step>

  <Step title="Access a document by MKK disclosure index">
    If you have the MKK disclosure index string, you can fetch the corresponding document directly without knowing its internal numeric `id`.

    ```bash theme={null}
    curl https://mkk-roan.vercel.app/api/disclosures/FCH2023Q4
    ```

    The response is identical to `GET /documents/{docId}`. You can append `?include_raw=true` to this endpoint as well.
  </Step>
</Steps>
