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

# Search app code

> <Info>This API is in beta. Endpoints, fields, and behavior may still change, so avoid depending on it in production.</Info>

Finds the lines in the app's source files that contain some text, the way the app editor's search does.

The text is matched literally, not as a pattern, and the match ignores case unless you set `case_sensitive`. Each result lists the matching lines of one file with their line numbers and up to 300 characters of the line around the match.

Search covers the files [List app code files](/api-reference/list-app-code-files) returns for the same `branch_id`. Files over 5 MB and files that aren't text are skipped and counted in `skipped_files`. A search stops after 500 matching lines or 10 seconds, and `truncated` is then `true`, so narrow the text if you need every match.

Reads come from the app's live sandbox, the same files the app editor shows, including changes that haven't been published yet. If no sandbox is running, the call starts one, so the first call after a quiet period takes noticeably longer than later ones.

Set `branch_id` to read a [branch](/developers/references/app-management/get-started/concepts#branches)'s files instead of main's. Each branch has its own sandbox, so the first read of a branch also takes longer. A merged branch can't be read: the call returns a 409. On an app imported from GitHub, reading a merged branch can instead return the files as they were when the branch was created, so don't rely on it there.

This is limited to 60 requests per minute per app for each workspace's personal API keys, so every key in a workspace shares one allowance. Some workspaces have a different limit.

<Note>This endpoint accepts a personal API key belonging to a user with editor access to the app. A read-only key is refused even though this endpoint only reads, and workspace API keys are not accepted.</Note>



## OpenAPI

````yaml /developers/references/app-management/app-management-openapi.json post /api/apps/{app_id}/code/search
openapi: 3.1.0
info:
  title: Base44 App Management API
  version: 1.0.0
servers:
  - url: https://app.base44.com
security:
  - PersonalAccessTokenAuth: []
paths:
  /api/apps/{app_id}/code/search:
    post:
      summary: Search app code
      description: >-
        <Info>This API is in beta. Endpoints, fields, and behavior may still
        change, so avoid depending on it in production.</Info>


        Finds the lines in the app's source files that contain some text, the
        way the app editor's search does.


        The text is matched literally, not as a pattern, and the match ignores
        case unless you set `case_sensitive`. Each result lists the matching
        lines of one file with their line numbers and up to 300 characters of
        the line around the match.


        Search covers the files [List app code
        files](/api-reference/list-app-code-files) returns for the same
        `branch_id`. Files over 5 MB and files that aren't text are skipped and
        counted in `skipped_files`. A search stops after 500 matching lines or
        10 seconds, and `truncated` is then `true`, so narrow the text if you
        need every match.


        Reads come from the app's live sandbox, the same files the app editor
        shows, including changes that haven't been published yet. If no sandbox
        is running, the call starts one, so the first call after a quiet period
        takes noticeably longer than later ones.


        Set `branch_id` to read a
        [branch](/developers/references/app-management/get-started/concepts#branches)'s
        files instead of main's. Each branch has its own sandbox, so the first
        read of a branch also takes longer. A merged branch can't be read: the
        call returns a 409. On an app imported from GitHub, reading a merged
        branch can instead return the files as they were when the branch was
        created, so don't rely on it there.


        This is limited to 60 requests per minute per app for each workspace's
        personal API keys, so every key in a workspace shares one allowance.
        Some workspaces have a different limit.


        <Note>This endpoint accepts a personal API key belonging to a user with
        editor access to the app. A read-only key is refused even though this
        endpoint only reads, and workspace API keys are not accepted.</Note>
      operationId: search_api_apps__app_id__code_search_post
      parameters:
        - name: app_id
          in: path
          required: true
          schema:
            type: string
            description: ID of the app whose code to read.
            title: App Id
          description: ID of the app whose code to read.
          example: 6820f3a4e7b91d003c45a1f2
        - name: branch_id
          in: query
          required: false
          schema:
            type: string
            description: >-
              ID of the branch to work on, as returned by [List
              branches](/api-reference/list-branches). Omit it to work on the
              app's main branch.
            title: Branch Id
          description: >-
            ID of the branch to work on, as returned by [List
            branches](/api-reference/list-branches). Omit it to work on the
            app's main branch.
          example: 68f1a2b3c4d5e6f708192a3b
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SearchFiles'
      responses:
        '200':
          description: The matching lines, grouped by file.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchResults'
        '401':
          description: Missing or invalid credentials.
        '403':
          description: >-
            You don't have editor access to this app, your API key is read-only,
            or you used a workspace API key.
        '404':
          description: App not found, or no branch you can see has this `branch_id`.
        '409':
          description: >-
            The branch in `branch_id` was merged (`extra_data.reason` is
            `branch_not_active`).
        '422':
          description: >-
            `query` is missing, shorter than 2 or longer than 200 characters,
            only whitespace, or spans more than one line.
        '429':
          description: >-
            Rate limit exceeded. The base limit is 60 requests per minute. See
            [Rate
            limits](/developers/references/apps-api/get-started/rate-limits) for
            the multiplier your plan gets.
      security:
        - PersonalAccessTokenAuth:
            - full_access
components:
  schemas:
    SearchFiles:
      properties:
        query:
          type: string
          maxLength: 200
          minLength: 2
          title: Query
          description: >-
            Text to find, 2 to 200 characters on a single line. It's matched
            literally.
          example: useState(
        case_sensitive:
          type: boolean
          title: Case Sensitive
          description: Whether the match respects case.
          default: false
          example: false
      type: object
      required:
        - query
      title: SearchFiles
      description: The text to find.
    SearchResults:
      properties:
        files:
          items:
            $ref: '#/components/schemas/SearchFileResult'
          type: array
          title: Files
          description: Each file with at least one match.
          example:
            - matches:
                - line_number: 12
                  preview: '  const [count, setCount] = useState(0);'
              path: src/pages/Home.jsx
        truncated:
          type: boolean
          title: Truncated
          description: >-
            `true` when the search stopped at 500 matching lines or 10 seconds,
            so there can be more matches.
          example: false
        skipped_files:
          type: integer
          title: Skipped Files
          description: >-
            Number of files left out of the search because they're over 5 MB or
            aren't text.
          example: 0
      type: object
      required:
        - files
        - truncated
        - skipped_files
      title: SearchResults
      description: The files that contain the text.
    SearchFileResult:
      properties:
        path:
          type: string
          title: Path
          description: Path of the file, relative to the app root.
          example: src/pages/Home.jsx
        matches:
          items:
            $ref: '#/components/schemas/SearchMatch'
          type: array
          title: Matches
          description: The file's matching lines, in order.
          example:
            - line_number: 12
              preview: '  const [count, setCount] = useState(0);'
      type: object
      required:
        - path
        - matches
      title: SearchFileResult
      description: The matching lines in one file.
    SearchMatch:
      properties:
        line_number:
          type: integer
          title: Line Number
          description: Number of the line in the file, starting at 1.
          example: 12
        preview:
          type: string
          title: Preview
          description: The line, cut to at most 300 characters around the match.
          example: '  const [count, setCount] = useState(0);'
      type: object
      required:
        - line_number
        - preview
      title: SearchMatch
      description: One line that contains the text.
  securitySchemes:
    PersonalAccessTokenAuth:
      type: http
      scheme: bearer
      description: >-
        Personal access token, sent as `Authorization: Bearer <token>`. Each
        operation lists the permission it needs: `read_only` or `full_access`. A
        full-access token can call every operation. A read-only token can call
        only the operations that list `read_only`; anything else returns 403
        `read_only_credential_route_not_allowed`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.