# Search the app's code for literal text.

POST https://services.leadconnectorhq.com/ai-builder-api/cli/projects/{projectId}/sandbox/search

Finds where text appears in the app's source files (ts, tsx, js, jsx, vue, json, md, css), with dependencies and build output left out. The text is matched literally, not as a pattern. Read the files it finds with `POST .../sandbox/view`.

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `clientportal-ai.readonly`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | The API version. |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `projectId` | string | Yes | Project identifier. |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "HighLevel API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/ai-builder-api/cli/projects/{projectId}/sandbox/search": {
      "post": {
        "summary": "Search the app's code for literal text.",
        "operationId": "searchTheAppsCodeForLiteralText",
        "description": "Finds where text appears in the app's source files (ts, tsx, js, jsx, vue, json, md, css), with dependencies and build output left out. The text is matched literally, not as a pattern. Read the files it finds with `POST .../sandbox/view`.",
        "parameters": [
          {
            "name": "projectId",
            "in": "path",
            "required": true,
            "description": "Project identifier.",
            "schema": {
              "type": "string",
              "pattern": "^prj_[A-Za-z0-9]+$",
              "example": "prj_01HXQ8Z6J9K2"
            }
          },
          {
            "name": "Version",
            "in": "header",
            "required": true,
            "description": "The API version.",
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CliSandboxSearchRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The matching lines, at most `maxResults`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CliSandboxSearchResult"
                }
              }
            }
          },
          "503": {
            "description": "The app's sandbox was asleep and is starting (`sandbox_starting`). Retry in about a minute; the app's context reports `ready` once it is up."
          }
        },
        "security": [
          {
            "bearer": [
              "clientportal-ai.readonly"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "A sub-account access token: a Marketplace app's OAuth token or a Private Integration Token."
      }
    },
    "schemas": {
      "CliSandboxSearchRequest": {
        "type": "object",
        "required": [
          "query"
        ],
        "properties": {
          "query": {
            "type": "string",
            "minLength": 2,
            "maxLength": 200,
            "description": "The text to find, matched literally. It cannot start with '-'.",
            "example": "useCourses"
          },
          "paths": {
            "type": "array",
            "maxItems": 2,
            "description": "Folders to search, relative to the workspace root; the whole app when absent.",
            "example": [
              "apps/clientportal-custom-app"
            ],
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 256,
              "description": "A folder, relative to the workspace root, with no '..'.",
              "example": "apps/clientportal-custom-app"
            }
          },
          "ignoreCase": {
            "type": "boolean",
            "description": "Match regardless of case.",
            "example": false
          },
          "maxResults": {
            "type": "integer",
            "minimum": 1,
            "maximum": 60,
            "description": "The most matching lines to return; 30 by default.",
            "example": 30
          }
        },
        "title": "CliSandboxSearchRequest"
      },
      "CliSandboxSearchResult": {
        "type": "object",
        "required": [
          "query",
          "hits",
          "hitCount",
          "truncated",
          "searchedPaths"
        ],
        "properties": {
          "query": {
            "type": "string",
            "description": "The text searched for.",
            "example": "useCourses"
          },
          "hits": {
            "type": "array",
            "description": "The matching lines.",
            "example": [
              {
                "path": "apps/clientportal-custom-app/pages/learn.vue",
                "line": 12,
                "preview": "const { courses } = useCourses()"
              }
            ],
            "items": {
              "type": "object",
              "required": [
                "path",
                "line",
                "preview"
              ],
              "properties": {
                "path": {
                  "type": "string",
                  "description": "The file, relative to the workspace root.",
                  "example": "apps/clientportal-custom-app/pages/learn.vue"
                },
                "line": {
                  "type": "integer",
                  "description": "The matching line's number.",
                  "example": 12
                },
                "preview": {
                  "type": "string",
                  "description": "The matching line, trimmed to 200 characters.",
                  "example": "const { courses } = useCourses()"
                }
              }
            }
          },
          "hitCount": {
            "type": "integer",
            "description": "How many lines matched, up to `maxResults`.",
            "example": 1
          },
          "truncated": {
            "type": "boolean",
            "description": "True when more lines matched than were returned.",
            "example": false
          },
          "searchedPaths": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "The folders searched.",
            "example": [
              "."
            ]
          }
        },
        "title": "CliSandboxSearchResult"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/search' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "query": "useCourses",
  "paths": [
    "apps/clientportal-custom-app"
  ],
  "ignoreCase": false,
  "maxResults": 30
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "query": "useCourses",
      "paths": [
        "apps/clientportal-custom-app"
      ],
      "ignoreCase": false,
      "maxResults": 30
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/search', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/ai-builder-api/cli/projects/{projectId}/sandbox/search"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "query": "useCourses",
    "paths": [
        "apps/clientportal-custom-app"
    ],
    "ignoreCase": false,
    "maxResults": 30
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/search',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "query": "useCourses",
  "paths": [
    "apps/clientportal-custom-app"
  ],
  "ignoreCase": false,
  "maxResults": 30
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/search")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"query\":\"useCourses\",\"paths\":[\"apps/clientportal-custom-app\"],\"ignoreCase\":false,\"maxResults\":30}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/search"
  payload := strings.NewReader(`{
  "query": "useCourses",
  "paths": [
    "apps/clientportal-custom-app"
  ],
  "ignoreCase": false,
  "maxResults": 30
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/search")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "query": "useCourses",
  "paths": [
    "apps/clientportal-custom-app"
  ],
  "ignoreCase": false,
  "maxResults": 30
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "query": "useCourses",
  "paths": [
    "apps/clientportal-custom-app"
  ],
  "ignoreCase": false,
  "maxResults": 30
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/ai-builder-api/cli/projects/<projectId>/sandbox/search' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
