# Search companies

You can search for companies by the value of their attributes in order to fetch exactly the companies you want.
To search for companies, send a `POST` request to `https://api.intercom.io/companies/search`, with a query object in the body defining your filters.
Note that the API does not include companies who have no associated users in search results.
Search queries can be complex, so optimizing them can help the performance of your search.
Use the `AND` and `OR` operators to combine multiple filters to get the exact results you need and utilize
pagination to limit the number of results returned. The default is `15` results per page.
See the [pagination section](https://developers.intercom.com/docs/build-an-integration/learn-more/rest-apis/pagination/#example-search-conversations-request) for more details on how to use the `starting_after` param.
### Nesting & Limitations
You can nest these filters in order to get even more granular insights that pinpoint exactly what you need. Example: (1 OR 2) AND (3 OR 4).
There are some limitations to the amount of multiple's there can be:
* There's a limit of max 2 nested filters
* There's a limit of max 15 filters for each AND or OR group

### Accepted Fields
Most keys listed as part of the Companies Model are searchable. The value you search for has to match the accepted type, otherwise the query will fail (ie. as `created_at` accepts a date, the `value` cannot be a string such as `"foobar"`).
| Field | Type |
|  --- | --- |
| company_id | String |
| name | String |
| created_at | Date (UNIX Timestamp) |
| updated_at | Date (UNIX Timestamp) |
| remote_created_at | Date (UNIX Timestamp) |
| last_request_at | Date (UNIX Timestamp) |
| monthly_spend | Integer |
| session_count | Integer |
| user_count | Integer |
| tag_id | String |
| custom_attributes.{attribute_name} | String |

The `plan.id` and `plan.name` fields are not searchable and return a `400` error with code `invalid_field`.
### Accepted Operators
The table below shows the operators you can use to define how you want to search for the value. The operator should be put in as a string (`"="`). The operator has to be compatible with the field's type (eg. you cannot search with `>` for a given string value as it's only compatible for integer's and dates). Searching by `tag_id` supports only the `=` and `!=` operators. The `IN` and `NIN` operators are not supported for Date fields.
| Operator | Valid Types | Description |
|  --- | --- | --- |
| = | All | Equals |
| != | All | Doesn't Equal |
| IN | All except Date and tag_id | In<br>Shortcut for `OR` queries<br>Values must be in Array |
| NIN | All except Date and tag_id | Not In<br>Shortcut for `OR !` queries<br>Values must be in Array |
| > | Integer<br>Date (UNIX Timestamp) | Greater than |
| < | Integer<br>Date (UNIX Timestamp) | Lower than |
| ~ | String | Contains |
| !~ | String | Doesn't Contain |
| ^ | String | Starts With |
| $ | String | Ends With |

### Sorting
Pass an optional `sort` object with a `field` and an `order` (`ascending` or `descending`; defaults to `descending`) to order the results. An invalid `order` returns a `400` error with code `invalid_sort_order`. `tag_id` can be used as a filter but not as a sort field.
### Pagination
Pass an optional `pagination` object with `per_page` and `starting_after`. `per_page` defaults to 15 and must be between 1 and 150; anything else returns a `400` error with code `invalid_per_page`. Take `starting_after` from `pages.next` in the previous response, and send it with the same `sort` you used for that response. A cursor from a sort on a text field such as `name`, sent with a sort on a number or date field (or the other way round), returns a `400` error with code `client_error`. Leaving out `sort` sorts by `last_request_at`, a date. A cursor sent with a different sort of the same kind is accepted, but the page it returns doesn't follow on from the previous one.
Requires the `read_users_companies` OAuth scope.

Endpoint: POST /companies/search
Version: 2.17
Security: bearerAuth

## Header parameters:

  - `Intercom-Version` (string)

## Request fields (application/json):

  - `query` (any, required)

  - `query.field` (string)
    The accepted field that you want to search on.
    Example: created_at

  - `query.operator` (string)
    The accepted operators you can use to define how you want to search for the value. Operator support depends on the field's data type. The breakdown below is for Contacts search; the other search endpoints that share this schema accept a different set per field:
- `string` fields: `=`, `!=`, `IN`, `NIN`, `~`, `!~`, `^`, `$`
- `tag_id`: `=` and `!=` only. Every other operator returns an error.
- `boolean` fields: `=`, `!=`, `IN`, `NIN`
- `integer` fields: `=`, `!=`, `IN`, `NIN`, `<`, `>`, `<=`, `>=`
- `datetime` fields (standard contact timestamps such as `created_at` and `last_seen_at`): `=`, `!=`, `<`, `>`, `<=`, `>=`. Filtering is on the exact second, in UTC.
- `date` fields (Date custom attributes): `=`, `<`, `>` only. `!=`, `<=`, and `>=` are not supported and return an error. Values are truncated to a whole UTC day.
    Enum: "=", "!=", "IN", "NIN", "<", "<=", ">", ">=", "~", "!~", "^", "$"

  - `query.value` (any)
    The value that you want to search on.
    Example: 73732934

  - `query.operator` (string)
    An operator to allow boolean inspection between multiple fields.
    Enum: "AND", "OR"

  - `query.value` (any)

  - `pagination` (object)

  - `pagination.per_page` (integer)
    The number of results to fetch per page.
    Example: 2

  - `pagination.starting_after` (string)
    The cursor to use in the next request to get the next page of results.
    Example: your-cursor-from-response

  - `sort` (object)
    An optional object to sort the results by.

  - `sort.field` (string)
    The field to sort the results on.
    Example: created_at

  - `sort.order` (string)
    The order to sort the results in. Defaults to `descending` when omitted. Values other than `ascending` or `descending` return a `400` error with code `invalid_sort_order`.
    Enum: "ascending", "descending"

## Response 200 fields (application/json):

  - `type` (string)
    The type of object - `list`.
    Enum: "list"

  - `pages` (object)
    Cursor-based pagination is a technique used in the Intercom API to navigate through large amounts of data.
A "cursor" or pointer is used to keep track of the current position in the result set, allowing the API to return the data in small chunks or "pages" as needed.

  - `pages.type` (string)
    the type of object `pages`.
    Enum: "pages"

  - `pages.page` (integer)
    The current page
    Example: 1

  - `pages.next` (object)
    Fetch the next page by sending this `starting_after` cursor. Omitted on the last page.

  - `pages.next.page` (integer)
    The number of the next page
    Example: 2

  - `pages.next.starting_after` (string)
    The cursor to send in the next request to get the next page of results.
    Example: your-cursor-from-response

  - `pages.per_page` (integer)
    Number of results per page
    Example: 2

  - `pages.total_pages` (integer)
    Total number of pages
    Example: 13

  - `total_count` (integer)
    The total number of companies.
    Example: 100

  - `data` (array)
    An array containing Company Objects.

  - `data.type` (string)
    Value is `company`
    Enum: "company"

  - `data.id` (string)
    The Intercom defined id representing the company.
    Example: 531ee472cce572a6ec000006

  - `data.name` (string)
    The name of the company. Returned HTML-escaped, for example `&` as `&amp;`.
    Example: Blue Sun

  - `data.app_id` (string)
    The Intercom defined code of the workspace the company is associated to.
    Example: ecahpwf5

  - `data.plan` (object)

  - `data.plan.type` (string)
    Value is always "plan"
    Example: plan

  - `data.plan.id` (string)
    The id of the plan
    Example: 269315

  - `data.plan.name` (string)
    The name of the plan
    Example: Pro

  - `data.company_id` (string)
    The company id you have defined for the company. Returned HTML-escaped, for example `&` as `&amp;`.
    Example: 6

  - `data.remote_created_at` (integer)
    The time the company was created by you.
    Example: 1663597223

  - `data.created_at` (integer)
    The time the company was added in Intercom.
    Example: 1663597223

  - `data.updated_at` (integer)
    The last time the company was updated.
    Example: 1663597223

  - `data.last_request_at` (integer)
    The time the company last recorded making a request.
    Example: 1663597223

  - `data.size` (integer)
    The number of employees in the company.
    Example: 100

  - `data.website` (string)
    The URL for the company website.
    Example: https://www.intercom.com

  - `data.industry` (string)
    The industry that the company operates in.
    Example: Software

  - `data.monthly_spend` (integer)
    How much revenue the company generates for your business.
    Example: 100

  - `data.session_count` (integer)
    How many sessions the company has recorded.
    Example: 100

  - `data.user_count` (integer)
    The number of users in the company.
    Example: 100

  - `data.tags` (object)
    The list of tags associated with the company

  - `data.tags.type` (string)
    The type of the object
    Enum: "tag.list"

  - `data.tags.tags` (array)

  - `data.tags.tags.type` (string)
    value is "tag"
    Example: tag

  - `data.tags.tags.id` (string)
    The id of the tag
    Example: 123456

  - `data.tags.tags.name` (string)
    The name of the tag
    Example: Test tag

  - `data.segments` (object)
    Always returned empty. Fetch a company's segments with the list attached segments endpoint.

  - `data.segments.type` (string)
    The type of the object
    Enum: "segment.list"

  - `data.segments.segments` (array)

  - `data.segments.segments.type` (string)
    The type of object.
    Enum: "segment"

  - `data.segments.segments.id` (string)
    The unique identifier representing the segment.
    Example: 56203d253cba154d39010062

  - `data.segments.segments.name` (string)
    The name of the segment.
    Example: Active

  - `data.segments.segments.created_at` (integer)
    The time the segment was created.
    Example: 1394621988

  - `data.segments.segments.updated_at` (integer)
    The time the segment was updated.
    Example: 1394622004

  - `data.segments.segments.person_type` (string)
    Type of the contact: contact (lead) or user.
    Enum: "contact", "user"

  - `data.segments.segments.count` (integer)
    The number of items in the user segment. It's returned when the request has `include_count` with a value. A company segment only gets a count when a contact segment has the same name, and it shows that segment's count.
    Example: 3

  - `data.notes` (object)
    The list of notes associated with the company

  - `data.notes.type` (string)
    The type of the object
    Enum: "note.list"

  - `data.notes.data` (array)
    The notes on the company, newest first.

  - `data.notes.data.type` (string)
    String representing the object's type. Always has the value `note`.
    Example: note

  - `data.notes.data.id` (string)
    The id of the note.
    Example: 17495962

  - `data.notes.data.url` (string)
    The relative URL of the note.
    Example: /notes/17495962

  - `data.notes.data.body` (string)
    The body text of the note.
    Example: <p>Text for the note.</p>

  - `data.notes.url` (string)
    The relative URL of the company's notes.
    Example: /companies/531ee472cce572a6ec000006/notes

  - `data.notes.total_count` (integer)
    The number of notes in `data`.
    Example: 1

  - `data.notes.has_more` (boolean)
    Always `false`. Every note on the company is returned in `data`.
    Example: false

## Response 400 fields (application/json):

  - `type` (string, required)
    The type is error.list
    Example: error.list

  - `request_id` (string)
    Example: f93ecfa8-d08a-4325-8694-89aeb89c8f85

  - `errors` (array, required)
    An array of one or more error objects

  - `errors.code` (any, required)
    A string indicating the kind of error, used to further qualify the HTTP response code. A few request validation errors send an HTTP status code as an integer here instead, for example `422`.
    Example: unauthorized

  - `errors.message` (string)
    Optional. Human readable description of the error.
    Example: Access Token Invalid

## Response 401 fields (application/json):

  - `type` (string, required)
    The type is error.list
    Example: error.list

  - `request_id` (string)
    Example: f93ecfa8-d08a-4325-8694-89aeb89c8f85

  - `errors` (array, required)
    An array of one or more error objects

  - `errors.code` (any, required)
    A string indicating the kind of error, used to further qualify the HTTP response code. A few request validation errors send an HTTP status code as an integer here instead, for example `422`.
    Example: unauthorized

  - `errors.message` (string)
    Optional. Human readable description of the error.
    Example: Access Token Invalid

## Response 503 fields (application/json):

  - `type` (string, required)
    The type is error.list
    Example: error.list

  - `request_id` (string)
    Example: f93ecfa8-d08a-4325-8694-89aeb89c8f85

  - `errors` (array, required)
    An array of one or more error objects

  - `errors.code` (any, required)
    A string indicating the kind of error, used to further qualify the HTTP response code. A few request validation errors send an HTTP status code as an integer here instead, for example `422`.
    Example: unauthorized

  - `errors.message` (string)
    Optional. Human readable description of the error.
    Example: Access Token Invalid

