# 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.

Endpoint: POST /companies/search
Version: Preview
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)

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

  - `pages.next.starting_after` (string)
    The cursor to use 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.
    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.
    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)
    The list of segments associated with the company

  - `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 `include_count=true` is included in the request.
    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.notes` (array)

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

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

  - `data.notes.notes.created_at` (integer)
    The time the note was created.
    Example: 1674589321

  - `data.notes.notes.company` (object)
    Represents the company that the note was created about.

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

  - `data.notes.notes.company.id` (string)
    The id of the company.
    Example: 6329bd9ffe4e2e91dac76188

  - `data.notes.notes.author` (object)
    Admins are teammate accounts that have access to a workspace.

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

  - `data.notes.notes.author.id` (string)
    The id representing the admin.
    Example: 1295

  - `data.notes.notes.author.name` (string)
    The name of the admin.
    Example: Joe Example

  - `data.notes.notes.author.email` (string)
    The email of the admin.
    Example: jdoe@example.com

  - `data.notes.notes.author.job_title` (string)
    The job title of the admin.
    Example: Associate

  - `data.notes.notes.author.away_mode_enabled` (boolean)
    Identifies if this admin is currently set in away mode.
    Example: false

  - `data.notes.notes.author.away_mode_reassign` (boolean)
    Identifies if this admin is set to automatically reassign new conversations to the apps default inbox.
    Example: false

  - `data.notes.notes.author.away_status_reason_id` (integer)
    The unique identifier of the away status reason
    Example: 12345

  - `data.notes.notes.author.has_inbox_seat` (boolean)
    Identifies if this admin has a paid inbox seat to restrict/allow features that require them.
    Example: true

  - `data.notes.notes.author.team_ids` (array)
    This object represents the avatar associated with the admin.
    Example: [814865]

  - `data.notes.notes.author.avatar` (string)
    Image for the associated team or teammate
    Example: https://picsum.photos/200/300

  - `data.notes.notes.author.team_priority_level` (object)
    Admin priority levels for teams

  - `data.notes.notes.author.team_priority_level.primary_team_ids` (array)
    The primary team ids for the team
    Example: [814865]

  - `data.notes.notes.author.team_priority_level.secondary_team_ids` (array)
    The secondary team ids for the team
    Example: [493881]

  - `data.notes.notes.author.role` (object)
    The role assigned to this admin. Only present if the admin has a role assigned.

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

  - `data.notes.notes.author.role.id` (string)
    The id of the role.
    Example: 1

  - `data.notes.notes.author.role.name` (string)
    The name of the role.
    Example: Support Agent

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

## 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` (string, required)
    A string indicating the kind of error, used to further qualify the HTTP response code
    Example: unauthorized

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

  - `errors.field` (string)
    Optional. Used to identify a particular field or query parameter that was in error.
    Example: email

## 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` (string, required)
    A string indicating the kind of error, used to further qualify the HTTP response code
    Example: unauthorized

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

  - `errors.field` (string)
    Optional. Used to identify a particular field or query parameter that was in error.
    Example: email

