# Search documents

Find readable files by a case-insensitive filename match, optionally within a folder. Use SearchDocumentContent to search the text inside documents.

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

## Access & visibility

Allow `documents.SearchDocuments` 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 |
| --- | --- | --- | --- |
| `scope` | string | Yes | Document collection: org is shared with the workspace; user is private to the calling person; resources contains the workspace's supplied resources. A move changes who can read the document; omit scope when only changing its folder. Allowed: `"org"`, `"user"`, `"resources"`. |
| `query` | string | Yes | Text to search for. At least 1 character. At most 200 characters. |
| `path_prefix` | string | No | Folder-path prefix used to narrow the search. |
| `limit` | integer | No | Maximum number of matching results to return. This operation does not provide a continuation cursor. Maximum: 200. Greater than 0. |

## 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](#document-response-items) | Yes | Documents matching the search text in the selected collection and optional folder prefix, bounded by limit. This operation has no cursor pagination. |

### Document · response.items[]

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file_id` | 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` | string | Yes | Original filename, including its extension. |
| `size_bytes` | number or null | Yes | File size in bytes. Null for a document without a downloadable binary file. |
| `content_type` | string or null | Yes | Media type of the file, such as application/pdf. Null when no binary file exists. |
| `path` | string | Yes | Folder path within the selected document collection. An empty string is its root. |
| `created_at` | number | Yes | Creation time in Unix milliseconds. |
| `owner_account_id` | string or null | Yes | Account that owns a private document, or null for a workspace document. |
| `created_by` | string or null | Yes | Account that created the record, or null when no account is recorded. |
| `kind` | string or null | Yes | Document origin or format: user_upload, agent_generated, signed_document and other file categories; text_document identifies collaborative text, while document identifies a generated Brigg document. |
| `scan_status` | string or null | Yes | Malware scan state. Threats and failed scans block downloads. An unsupported file cannot be processed; only its original uploader can retrieve it as a forced download. Null is not proof of readiness. |
| `document_kind` | string | Yes | `file` = an uploaded file (its original bytes); `text_document` = a collaborative Tekstdokument (markdown); `generated_document` = a formatted document Brigg generated («Lag dokument»). Allowed: `"file"`, `"text_document"`, `"generated_document"`. |

## 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.SearchDocuments' \
  -H "Authorization: Bearer $BRIGG_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "scope": "org",
  "query": "onboarding"
}'
```

#### TypeScript


```typescript
const response = await fetch("https://api.brigg.app/v1/operations/documents.SearchDocuments", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.BRIGG_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "scope": "org",
    "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 = {
  "scope": "org",
  "query": "onboarding"
}
request = Request(
    "https://api.brigg.app/v1/operations/documents.SearchDocuments",
    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",
      "size_bytes": 48231,
      "content_type": "application/pdf",
      "path": "Proposals",
      "created_at": 1794301200000,
      "owner_account_id": null,
      "created_by": "account_alex",
      "kind": "user_upload",
      "scan_status": "clean",
      "document_kind": "file"
    }
  ]
}
```

## JSON schemas


```json-schema-request
{
  "type": "object",
  "properties": {
    "scope": {
      "type": "string",
      "enum": [
        "org",
        "user",
        "resources"
      ],
      "description": "Document collection: org is shared with the workspace; user is private to the calling person; resources contains the workspace's supplied resources. A move changes who can read the document; omit scope when only changing its folder."
    },
    "query": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "description": "Text to search for."
    },
    "path_prefix": {
      "type": "string",
      "description": "Folder-path prefix used to narrow the search."
    },
    "limit": {
      "type": "integer",
      "exclusiveMinimum": 0,
      "maximum": 200,
      "description": "Maximum number of matching results to return. This operation does not provide a continuation cursor."
    }
  },
  "required": [
    "scope",
    "query"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "scope": "org",
      "query": "onboarding"
    }
  ]
}
```


```json-schema-response
{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "file_id": {
            "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": {
            "type": "string",
            "examples": [
              "Proposal.pdf"
            ],
            "description": "Original filename, including its extension."
          },
          "size_bytes": {
            "type": [
              "number",
              "null"
            ],
            "description": "File size in bytes. Null for a document without a downloadable binary file.",
            "examples": [
              48231
            ]
          },
          "content_type": {
            "type": [
              "string",
              "null"
            ],
            "description": "Media type of the file, such as application/pdf. Null when no binary file exists.",
            "examples": [
              "application/pdf"
            ]
          },
          "path": {
            "type": "string",
            "description": "Folder path within the selected document collection. An empty string is its root.",
            "examples": [
              "Proposals"
            ]
          },
          "created_at": {
            "type": "number",
            "description": "Creation time in Unix milliseconds."
          },
          "owner_account_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "Account that owns a private document, or null for a workspace document.",
            "examples": [
              null
            ]
          },
          "created_by": {
            "type": [
              "string",
              "null"
            ],
            "examples": [
              "account_alex"
            ],
            "description": "Account that created the record, or null when no account is recorded."
          },
          "kind": {
            "type": [
              "string",
              "null"
            ],
            "description": "Document origin or format: user_upload, agent_generated, signed_document and other file categories; text_document identifies collaborative text, while document identifies a generated Brigg document.",
            "examples": [
              "user_upload"
            ]
          },
          "scan_status": {
            "type": [
              "string",
              "null"
            ],
            "description": "Malware scan state. Threats and failed scans block downloads. An unsupported file cannot be processed; only its original uploader can retrieve it as a forced download. Null is not proof of readiness.",
            "examples": [
              "clean"
            ]
          },
          "document_kind": {
            "type": "string",
            "enum": [
              "file",
              "text_document",
              "generated_document"
            ],
            "description": "`file` = an uploaded file (its original bytes); `text_document` = a collaborative Tekstdokument (markdown); `generated_document` = a formatted document Brigg generated («Lag dokument»).",
            "examples": [
              "file"
            ]
          }
        },
        "required": [
          "file_id",
          "filename",
          "size_bytes",
          "content_type",
          "path",
          "created_at",
          "owner_account_id",
          "created_by",
          "kind",
          "scan_status",
          "document_kind"
        ],
        "additionalProperties": false,
        "title": "Document"
      },
      "description": "Documents matching the search text in the selected collection and optional folder prefix, bounded by limit. This operation has no cursor pagination."
    }
  },
  "required": [
    "items"
  ],
  "additionalProperties": false,
  "examples": [
    {
      "items": [
        {
          "file_id": "file_proposal",
          "filename": "Proposal.pdf",
          "size_bytes": 48231,
          "content_type": "application/pdf",
          "path": "Proposals",
          "created_at": 1794301200000,
          "owner_account_id": null,
          "created_by": "account_alex",
          "kind": "user_upload",
          "scan_status": "clean",
          "document_kind": "file"
        }
      ]
    }
  ]
}
```

