# Search companies

`POST /v4/records/companies/search`

Searches company records in the shared records index. Requires `companies:read`. The server always applies an immutable `type contains_exact company` filter before caller filters and excludes permanently deleted records; archived and deleted (`status` `delete`) records are included unless you filter on `status`.

All request fields are optional. Blank or omitted `query` defaults to `*`; omitted `limit` defaults to 10 and is clamped to 1-200; negative `offset` clamps to 0; omitted `sort` defaults to `created_at desc`; omitted `objects` defaults to false. Caller filters are additional constraints and cannot replace the server-owned type scope.

OAuth tokens of non-manager users only see records they can open in the app. `count` is exact once the records index has been rebuilt after impl-spec-1661; until then it may overstate matches.

### Filtering

`filters` is an array of filter **groups**. Groups are ANDed with each other and with the server's own scope (this record type; permanently deleted records excluded). Inside a group, `op` combines the clauses: `and`, `or`, or `not` (true when *not all* clauses match, i.e. NOT of their AND).

| Clause `op` | Value | Use for |
| --- | --- | --- |
| `eq` / `not_eq` | string, integer | exact, case-sensitive whole value; references, enums, select options |
| `contains` | string | whole-word, case-insensitive text match; several words match any of them |
| `contains_exact` | string token | one element of an array field (`types`, multiple select, one_to_many, `contacts`, `lists`, `categories`, `sources`) |
| `gt` / `gte` / `lt` / `lte` | RFC 3339 timestamp, `YYYY-MM-DD` day, integer | ranges on dates, days and counts |
| `between` | `[low, high]` (low ≤ high) | inclusive range on the same values |
| `exists` / `not_exists` | omit `value` | the attribute is present / absent |

Rules:

- `field` is an attribute name exactly as the record's `attributes` returns it; custom fields use their slug. Do not prefix with `meta.`.
- Timestamps need a full RFC 3339 value (`2026-01-01T00:00:00Z`); a bare date on a timestamp field matches nothing.
- Records with `status` `archived` or `delete` are included unless you filter on `status`.
- Empty custom fields may be stored as an empty string, which `exists` matches. To require a value, put `exists` and `not_eq ""` in one `and` group.
- Clauses on `type`, unknown group ops and unknown clause ops are ignored, not rejected. A request whose groups are all ignored searches without filters.
- A field no record has matches nothing; `not_exists` on it matches everything.
- `sort` accepts at most one entry; more than one is rejected. Sort on any attribute name, `asc` or `desc`.
- `query`: plain words match any word; a word ending in `*` is a required prefix. Use `*` (or omit it) to match all records and rely on filters.
- `near` (people, companies, jobs): `{"place": "Amsterdam", "radius_km": 40}` or `{"lat": 52.37, "lng": 4.9, "radius_km": 40}`, 1 to 500 km. Results come nearest first unless `sort` is given, each with `distance_km`. A place is resolved from this workspace's own addresses; 422 `PLACE_NOT_FOUND` asks for coordinates, and 503 `PLACE_LOOKUP_FAILED` means the lookup itself failed (retry). Only the primary location counts, and an address without coordinates is placed at its city's centre.
- `document_query` (people, companies, jobs): a keyword that must be in the record's document text (a person's parsed CV, the primary document of a company or job). At most 200 matching records are considered (`document_matches_truncated`).

#### Fields

| Field | Kind | Recommended ops | Value |
| --- | --- | --- | --- |
| `name` | text | `contains`, `eq`, `not_eq`, `exists`, `not_exists` | string |
| `status` | enum | `eq`, `not_eq` | `normal`, `archived`, `delete` |
| `created_at`, `updated_at`, `assigned_at`, `status_changed_at` | timestamp | `gte`, `gt`, `lt`, `lte`, `between`, `exists`, `not_exists` | RFC 3339 |
| `assigned_to`, `assigned_by`, `created_by` | user reference | `eq`, `not_eq`, `exists`, `not_exists` | user SqID |
| `image_id`, `primary_document_id` | image / file reference | `eq`, `exists`, `not_exists` | SqID |
| `image_url` | text | `exists`, `not_exists` | string |
| `types` | type tokens (array) | `contains_exact`, `exists`, `not_exists` | `company_type:<sqid>` |
| `access_level_id` | access level reference | `eq`, `not_eq`, `exists`, `not_exists` | SqID |
| `linkedin_url`, `github_url`, `twitter_url`, `facebook_url`, `instagram_url` | text (URL, from bookmarks) | `contains`, `eq`, `not_eq`, `exists`, `not_exists` | string; `exists` / `not_exists` test whether the record has one |
| `email_address`, `phone_number`, `address` | text | `contains`, `eq`, `not_eq`, `exists`, `not_exists` | string |
| `active_job_count` | integer | `gte`, `eq`, `not_eq`, `gt`, `lt`, `lte`, `between` | integer |
| `workflow_id` | workflow reference | `eq`, `not_eq`, `exists`, `not_exists` | workflow SqID |
| `workflow_phase_status`, `workflow_stage_status` | enum | `eq`, `not_eq`, `exists`, `not_exists` | phase / stage name, exact case (see `GET /v4/workflows/phases` and `GET /v4/workflows/stages`) |
| `workflow_phase_status_changed_at` | timestamp | `gte`, `gt`, `lt`, `lte`, `between`, `exists`, `not_exists` | RFC 3339 |
| `alias` | alias strings (array) | `contains_exact`, `exists`, `not_exists` | one alias, exact whole value; `query` also matches aliases |
| `city`, `state`, `country_code` | text (primary location) | `contains`, `eq`, `not_eq`, `exists`, `not_exists` | string; `eq` is the exact whole value (`country_code` is upper case, e.g. `NL`; `state` is the location's region), `contains` matches a word |
| `lists` | list tokens (array) | `contains_exact`, `exists`, `not_exists` | `list:<sqid>` (see `GET /v4/lists`) |
| `sources` | source tokens (array) | `contains_exact`, `exists`, `not_exists` | `source:<sqid>` (see `GET /v4/sources`) |
| `categories` | category tokens (array) | `contains_exact`, `exists`, `not_exists` | `category:<sqid>` (see `GET /v4/categories`) |

#### Custom fields

Custom fields are filtered by slug. The field's type decides the value:

| Custom field type | Recommended ops | Value |
| --- | --- | --- |
| text, string, markdown/html text (indexed as plain text) | `contains`, `eq`, `not_eq`, `exists`, `not_exists` | string |
| number (stored as text) | `eq`, `not_eq`, `exists`, `not_exists` | string, e.g. `"42"`; no ranges |
| date | `gte`, `gt`, `lt`, `lte`, `between`, `exists`, `not_exists` | RFC 3339 |
| boolean | `eq` | `"1"` for true; for "not true" use a `not` group with `eq "1"` |
| single select | `eq`, `not_eq`, `exists`, `not_exists` | `custom_field_option:<sqid>` |
| multiple select | `contains_exact`, `exists`, `not_exists` | `custom_field_option:<sqid>` |
| relationship, one_to_one | `eq`, `not_eq`, `exists`, `not_exists` | `<type>:<sqid>`, e.g. `person:Xy3` |
| relationship, one_to_many | `contains_exact`, `exists`, `not_exists` | `<type>:<sqid>` |

Option ids: send `"objects": true` once to get `data.objects` with `custom_field_option:<sqid>` labels.

Authentication (security requirement alternatives):

```json
[
  {
    "bearer_auth": [
      "companies:read"
    ]
  },
  {
    "oauth2_auth": [
      "companies:read"
    ]
  },
  {
    "apikey_auth": [
      "companies:read"
    ]
  }
]
```

- bearer_auth: http (bearer). API key or OAuth access token in Authorization header; scopes: companies:read
- oauth2_auth: oauth2. OAuth authorization code flow with mandatory S256 PKCE.; scopes: companies:read
- apikey_auth: apiKey, query api_key. API key in query string; scopes: companies:read

Request body: application/json

Type: object

Schema: [SearchRecordsRequest](https://docs.searchsoftware.nl/api/models/searchrecordsrequest.md)

- `query` (optional)
  Type: string
  
  Search query. Blank or omitted values default to *.
  
  Example:
  
  ```json
  "*"
  ```

- `limit` (optional)
  Type: integer, int32
  
  Maximum results. Defaults to 10 and is clamped to 1-200.
  
  Example:
  
  ```json
  10
  ```

- `offset` (optional)
  Type: integer, int32
  
  Zero-based offset. Defaults to 0 and negative values clamp to 0.
  
  Example:
  
  ```json
  0
  ```

- `filters` (optional)
  Type: array
  
  Additional filter groups ANDed with the immutable server-owned type scope.
  
  Items:
    Reference: [RecordSearchFilterGroup](https://docs.searchsoftware.nl/api/models/recordsearchfiltergroup.md); Type: object

- `sort` (optional)
  Type: array
  
  At most one entry; more than one is rejected. Empty or omitted defaults to created_at desc, or nearest first with near.
  
  Items:
    Reference: [RecordSearchSort](https://docs.searchsoftware.nl/api/models/recordsearchsort.md); Type: object

- `objects` (optional)
  Type: boolean
  
  Include hydrated object summaries in top-level data.objects when true. Defaults to false. File summaries (`file:<sqid>`) carry a `url`: a download URL that works without authentication until it expires, between 12 and 13 hours after the response. Request the record again for a fresh one.
  
  Example:
  
  ```json
  false
  ```

- `near` (optional)
  Reference: [RecordSearchNear](https://docs.searchsoftware.nl/api/models/recordsearchnear.md); Type: object

- `document_query` (optional)
  Type: string
  
  People, companies and jobs: a keyword that must appear in the record's document text (a person's parsed CV; the primary document of other records). At most 200 matching records are considered; data.document_matches_truncated says when there were more. Document text needs files:read, and through the MCP server the workspace's document text setting (403 DOCUMENT_TEXT_DISABLED).
  
  Example:
  
  ```json
  "AutoCAD"
  ```

Responses:

- 200: Record search results

Content type: application/json

Type: object

Schema: [RecordSearchResponse](https://docs.searchsoftware.nl/api/models/recordsearchresponse.md)

- `status` (required)
  Type: string
  
  Example:
  
  ```json
  "ok"
  ```

- `data` (required)
  Reference: [RecordSearchData](https://docs.searchsoftware.nl/api/models/recordsearchdata.md); Type: object

- 400: Invalid request body

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_BODY",
    "status_code": 400,
    "message": "Invalid request body"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_BODY",
    "status_code": 400,
    "message": "Invalid request body"
  }
}
```

- 401: Invalid API key

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_API_KEY",
    "status_code": 401,
    "message": "Invalid API key"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "INVALID_API_KEY",
    "status_code": 401,
    "message": "Invalid API key"
  }
}
```

- 403: Insufficient scope

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "FORBIDDEN",
    "status_code": 403,
    "message": "Insufficient scope"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "FORBIDDEN",
    "status_code": 403,
    "message": "Insufficient scope"
  }
}
```

- 422: Validation error

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "VALIDATION_FAILED",
    "status_code": 422,
    "message": "Validation failed"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "VALIDATION_FAILED",
    "status_code": 422,
    "message": "Validation failed"
  }
}
```

- 500: Internal server error

Content type: application/json

Type: unknown

Example:

```json
{
  "status": "error",
  "error": {
    "code": "INTERNAL_ERROR",
    "status_code": 500,
    "message": "Internal server error"
  }
}
```

allOf:
  Reference: [ErrorResponse](https://docs.searchsoftware.nl/api/models/errorresponse.md); Type: object

```json
{
  "status": "error",
  "error": {
    "code": "INTERNAL_ERROR",
    "status_code": 500,
    "message": "Internal server error"
  }
}
```

## Examples

### cURL

```bash
curl -X POST 'https://api.searchsoftware.nl/v4/records/companies/search' \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "query": "*",
  "filters": [
    {
      "op": "or",
      "clauses": [
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Xy3AbC"
        },
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Q9aZt2"
        }
      ]
    }
  ]
}'
```

### TypeScript

```typescript
const body = `{
  "query": "*",
  "filters": [
    {
      "op": "or",
      "clauses": [
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Xy3AbC"
        },
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Q9aZt2"
        }
      ]
    }
  ]
}`;

const response = await fetch('https://api.searchsoftware.nl/v4/records/companies/search', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "query": "*",
  "filters": [
    {
      "op": "or",
      "clauses": [
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Xy3AbC"
        },
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Q9aZt2"
        }
      ]
    }
  ]
}'''

response = requests.post(
    'https://api.searchsoftware.nl/v4/records/companies/search',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```

### Ruby

```ruby
require 'net/http'
require 'json'

uri = URI('https://api.searchsoftware.nl/v4/records/companies/search')
request = Net::HTTP::Post.new(uri)
request.body = <<-'BODY'.chomp
{
  "query": "*",
  "filters": [
    {
      "op": "or",
      "clauses": [
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Xy3AbC"
        },
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Q9aZt2"
        }
      ]
    }
  ]
}
BODY
request['Authorization'] = 'Bearer YOUR_TOKEN'
request['Content-Type'] = 'application/json'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) }
data = JSON.parse(response.body)
```

### Go

```go
package main

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

func main() {
  body := strings.NewReader(`{
  "query": "*",
  "filters": [
    {
      "op": "or",
      "clauses": [
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Xy3AbC"
        },
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Q9aZt2"
        }
      ]
    }
  ]
}`)
  req, _ := http.NewRequest("POST", "https://api.searchsoftware.nl/v4/records/companies/search", body)
  req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
  req.Header.Set("Content-Type", "application/json")
  resp, _ := http.DefaultClient.Do(req)
  defer resp.Body.Close()
  data, _ := io.ReadAll(resp.Body)
  fmt.Println(string(data))
}
```

### PHP

```php
<?php
$body = <<<'BODY'
{
  "query": "*",
  "filters": [
    {
      "op": "or",
      "clauses": [
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Xy3AbC"
        },
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Q9aZt2"
        }
      ]
    }
  ]
}
BODY;

$ch = curl_init('https://api.searchsoftware.nl/v4/records/companies/search');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer YOUR_TOKEN', 'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
```

### Rust

```rust
use reqwest;

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = reqwest::Client::new();
    let body = r#"{
  "query": "*",
  "filters": [
    {
      "op": "or",
      "clauses": [
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Xy3AbC"
        },
        {
          "field": "assigned_to",
          "op": "eq",
          "value": "Q9aZt2"
        }
      ]
    }
  ]
}"#;
    let response = client.post("https://api.searchsoftware.nl/v4/records/companies/search")
        .body(body)
        .header("Authorization", "Bearer YOUR_TOKEN")
        .header("Content-Type", "application/json")
        .send()
        .await?
        .text()
        .await?;
    println!("{}", response);
    Ok(())
}
```
