# Search document content

Search the text of readable files and return matching excerpts and file IDs. Results may combine keyword and semantic matching; scores are relative to this search, not percentages.

POST https://api.brigg.app/v1/operations/documents.SearchDocumentContent

## Access & visibility

Allow `documents.SearchDocumentContent` on your API key.

**Workspace access by default.** Private member data requires [approved member delegation](https://developer.brigg.app/authentication#member-delegation) through `Brigg-Act-As`; the key supplies permissions while private ownership and project boundaries remain enforced.

[Set up authentication](https://developer.brigg.app/authentication) · [Choose permissions](https://developer.brigg.app/permissions)

## Request fields

Send a JSON object with the following fields. Required fields must be included; omit optional fields you do not need.
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `query` | string | Yes | Text to search for. At least 1 character. At most 400 characters. |
| `limit` | integer | No | Maximum number of matching results to return. This operation does not provide a continuation cursor. Range: 1 to 50. |

## Response

Returns **200 OK** with a JSON body.

This operation has no continuation cursor. An empty `items` array means no matching visible results were returned.
| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `items` | array of [Document search result](#document-search-result-response-items) | Yes | Content matches in documents visible to the caller, bounded by limit. This operation has no cursor pagination. |

### Document search result · response.items[]

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file_id` | null or string | Yes | Stable file ID returned by documents.CompleteUpload, documents.ListDocuments or a document creation operation. Use the same ID for downloads, attachments and supported file-based workflows. Do not use a filename or storage path. |
| `filename` | null or string | Yes | Original filename, including its extension. |
| `scope` | null or string | Yes | Document collection containing this match: org, user or resources. |
| `path` | null or string | Yes | Folder path within the selected document collection. An empty string is its root. |
| `snippet` | string | Yes | A short excerpt showing why the result matched. |
| `score` | number | Yes | Search relevance score; use it for ranking results within this response, not as a probability. |
| `channels` | array of string | Yes | Search methods that contributed to this match. Each item: `"keyword"`, `"semantic"`. |

## Errors & retries

This operation reads data. It needs no idempotency key and can be retried after a transient failure.

For rate limits, follow the server’s retry guidance and back off. See [HTTP errors](https://developer.brigg.app/http#errors) and [safe retries and limits](https://developer.brigg.app/reliability).

| HTTP status | Code | What to do |
| --- | --- | --- |
| 400 | `invalid_json` | Send a JSON object with Content-Type: application/json. |
| 400 | `invalid_input` | Check the request fields and types. |
| 401 | `invalid_key` | The workspace API key is missing, invalid or revoked. |
| 403 | `forbidden` | Check the key’s operation and resource grants. If Brigg-Act-As is supplied, the key must be authorized to delegate to that member. |
| 404 | `not_found` | The requested operation or resource is not available to this credential. |
| 429 | `rate_limited` | Wait for Retry-After before retrying. |

## Next steps

- [Upload and download files](https://developer.brigg.app/files)

[Download OpenAPI](https://developer.brigg.app/openapi.json) · [Versioning & retirement](https://developer.brigg.app/versioning)

## Examples

### Example request

Fictional values. Replace IDs and business details with values from your workspace.
#### cURL


```sh
curl 'https://api.brigg.app/v1/operations/documents.SearchDocumentContent' \
  -H "Authorization: Bearer $BRIGG_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "query": "onboarding"
}'
```

#### TypeScript


```typescript
const response = await fetch("https://api.brigg.app/v1/operations/documents.SearchDocumentContent", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.BRIGG_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "query": "onboarding"
  }),
});
const result = await response.json();
if (!response.ok) throw new Error(`${response.status}: ${result.error} — ${result.message}`);
console.log(result);
```

#### Python


```python
import json
import os
from urllib.request import Request, urlopen
from urllib.error import HTTPError

payload = {
  "query": "onboarding"
}
request = Request(
    "https://api.brigg.app/v1/operations/documents.SearchDocumentContent",
    data=json.dumps(payload).encode("utf-8"),
    headers={
        "Authorization": f"Bearer {os.environ['BRIGG_API_KEY']}",
        "Content-Type": "application/json",
    },
    method="POST",
)
try:
    with urlopen(request) as response:
        print(json.load(response))
except HTTPError as error:
    print(error.code, json.load(error))
    raise
```

#### Response example


```json
{
  "items": [
    {
      "file_id": "file_proposal",
      "filename": "Proposal.pdf",
      "scope": "org",
      "path": "Proposals",
      "snippet": "The project includes onboarding and support.",
      "score": 0.82,
      "channels": []
    }
  ]
}
```

## JSON schemas


```json-schema-request
{
  "type": "object",
  "properties": {
    "query": {
      "type": "string",
      "minLength": 1,
      "maxLength": 400,
      "description": "Text to search for."
    },
    "limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 50,
      "description": "Maximum number of matching results to return. This operation does not provide a continuation cursor."
    }
  },
  "required": [
    "query"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "query": "onboarding"
    }
  ]
}
```


```json-schema-response
{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "title": "Document search result",
        "type": "object",
        "properties": {
          "file_id": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "string"
              }
            ],
            "description": "Stable file ID returned by documents.CompleteUpload, documents.ListDocuments or a document creation operation. Use the same ID for downloads, attachments and supported file-based workflows. Do not use a filename or storage path.",
            "examples": [
              "file_proposal"
            ]
          },
          "filename": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "string"
              }
            ],
            "description": "Original filename, including its extension.",
            "examples": [
              "Proposal.pdf"
            ]
          },
          "scope": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "string"
              }
            ],
            "description": "Document collection containing this match: org, user or resources.",
            "examples": [
              "org"
            ]
          },
          "path": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "type": "string"
              }
            ],
            "description": "Folder path within the selected document collection. An empty string is its root.",
            "examples": [
              "Proposals"
            ]
          },
          "snippet": {
            "type": "string",
            "description": "A short excerpt showing why the result matched.",
            "examples": [
              "The project includes onboarding and support."
            ]
          },
          "score": {
            "type": "number",
            "description": "Search relevance score; use it for ranking results within this response, not as a probability.",
            "examples": [
              0.82
            ]
          },
          "channels": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "keyword",
                "semantic"
              ]
            },
            "description": "Search methods that contributed to this match."
          }
        },
        "required": [
          "file_id",
          "filename",
          "scope",
          "path",
          "snippet",
          "score",
          "channels"
        ],
        "additionalProperties": false
      },
      "description": "Content matches in documents visible to the caller, bounded by limit. This operation has no cursor pagination."
    }
  },
  "required": [
    "items"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "items": [
        {
          "file_id": "file_proposal",
          "filename": "Proposal.pdf",
          "scope": "org",
          "path": "Proposals",
          "snippet": "The project includes onboarding and support.",
          "score": 0.82,
          "channels": []
        }
      ]
    }
  ]
}
```

