# Google Drive Search (`drive.search`)

Searches files in the connected Google Drive by full text, name or type and returns names, links, owners and dates.

Docs: https://primaryapi.com/docs/api-reference/google-drive/search

- Endpoint: `POST https://api.primaryapi.com/v1/run/drive.search`
- Category: Knowledge & Data · Platform: `google-drive` · Kind: search · Status: live
- Price: 1 credit per call. Every call costs the same, including calls that were retried automatically.
- Billing unit: per successful call
- Reliability: routed to a healthy upstream and retried automatically when an attempt fails; live 30-day status: `GET https://api.primaryapi.com/v1/status/apis?sku=drive.search`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `query` | string | no |  | max 500 chars | Words to look for in file names and contents (Drive full-text search). |
| `name` | string | no |  | max 200 chars | Only files whose name contains this text. |
| `mimeType` | string | no |  | max 200 chars; pattern: ^[\w.+-]+\/[\w.+-]+$ | Only files of this MIME type, for example "application/pdf" or "application/vnd.google-apps.folder". |
| `includeTrashed` | boolean | no | false |  | Include files in the trash (default false). |
| `orderBy` | enum | no | "modified" | one of: modified, created, name | Newest modified first (default), newest created first, or by name. A `query` (full-text search) keeps Drive’s own order. |
| `limit` | integer | no | 20 | 1–100 | Maximum number of results to return (1-100, default 20). |
| `cursor` | string | no |  |  | Opaque pagination cursor: pass the previous response's nextCursor. |
| `connection` | string | no |  | max 200 chars | Which connected account to use when the workspace has several for this provider: the customId you gave it (exact), its connection id ("con_…"), its handle (login, email or @handle) or its name. Optional; prefer the customId or id, which never match two accounts. |

Unknown fields are rejected with `400 invalid_input`. The routing controls `preferLatencyUnderMs` and `maxCredits` may be sent in the same JSON body.

## Output

When `output.found` is `true`, `output.data` has this shape:

| Field | Type | Description |
|---|---|---|
| `files` | object[] |  |
| `files[].id` | string |  |
| `files[].name` | string |  |
| `files[].mimeType` | string \| null |  |
| `files[].description` | string \| null |  |
| `files[].url` | string \| null | Opens the file in Google Drive |
| `files[].iconUrl` | string \| null |  |
| `files[].createdTime` | string \| null |  |
| `files[].modifiedTime` | string \| null |  |
| `files[].size` | integer \| null | Bytes (null for Google Docs, folders and shortcuts) |
| `files[].owners` | object[] |  |
| `files[].owners[].name` | string \| null |  |
| `files[].owners[].email` | string \| null |  |
| `files[].shared` | boolean \| null |  |
| `files[].starred` | boolean \| null |  |
| `files[].trashed` | boolean \| null |  |
| `files[].parents` | string[] | Parent folder id |
| `incompleteSearch` | boolean | True when Drive could not search every corpus |
| `nextCursor` | string \| null |  |

When the thing you asked about does not exist (or a search matches nothing) the call still succeeds: `output.found` is `false`, `output.data` is `null` and `output.reason` says why (`not_found`, `private`, `no_results`, …). Misses are free unless the notes below say misses are billed.

Pagination: pass the previous response’s `nextCursor` as `cursor` to get the next page; `nextCursor: null` means there are no more results.

## Example request

```bash
curl -sS -X POST "https://api.primaryapi.com/v1/run/drive.search" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"query":"Q4","limit":2}'
```

## Example response

_Values are placeholders that follow the output schema; `credits` is what this call would cost at the usual price._

```json
{
  "output": {
    "found": true,
    "data": {
      "files": [
        {
          "id": "1A2b3C4d5E6f7G8h9I0jKlMnOpQrStUvWxYz",
          "name": "Q4 plan",
          "mimeType": "application/vnd.google-apps.document",
          "description": "Draft plan for the fourth quarter",
          "url": "https://docs.google.com/document/d/1A2b3C4d5E6f7G8h9I0jKlMnOpQrStUvWxYz/edit?usp=drivesdk",
          "iconUrl": "https://drive-thirdparty.googleusercontent.com/16/type/application/vnd.google-apps.document",
          "createdTime": "2026-10-01T10:00:00.000Z",
          "modifiedTime": "2026-11-02T08:30:00.000Z",
          "size": null,
          "owners": [
            {
              "name": "Ada Example",
              "email": "ada@example.com"
            }
          ],
          "shared": false,
          "starred": true,
          "trashed": false,
          "parents": [
            "0AFolderIdExample"
          ]
        }
      ],
      "incompleteSearch": false,
      "nextCursor": "eyJ0IjoidG9rMiJ9"
    }
  },
  "provider": "PrimaryAPI",
  "credits": 1,
  "items": 1,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
  "nextCursor": null
}
```

## Pricing and reliability

- Usual price: 1 credit per call
- Price ceiling: the usual price, even when a call is retried. A quote’s `maxCredits` is the most a given call can cost; the `maxCredits` routing control caps it per call
- Live 30-day status, success rate, uptime and latency: `GET https://api.primaryapi.com/v1/status/apis?sku=drive.search`

## Errors to handle

`invalid_input`, `unauthorized`, `insufficient_balance`, `key_limit_reached`, `trial_cap_reached`, `forbidden`, `not_found`, `idempotency_conflict`, `rate_limited`, `all_sources_failed`, `service_unavailable`, `timeout`. See https://primaryapi.com/docs/errors.

## Notes

Runs as your connected Google account (read-only Drive access). Returns file metadata and links, not file contents. Run the call again to refresh them.

