# Search contacts

`POST /contacts/search`

> This is a subset of the full specification, limited to the `POST /contacts/search` operation.
>
> You can find the full specification here: /_bundle/docs/references/@2.12/rest-api/api.intercom.io.yaml

```yaml
openapi: 3.0.1
info:
  title: Intercom API
  version: '2.12'
  description: This is a subset of the full specification, limited to the `POST /contacts/search` operation. Components more than 3 `$ref` hops away are not included.
  contact:
    name: Intercom Developer Hub
    url: https://developers.intercom.com
  license:
    name: MIT
    url: https://spdx.org/licenses/MIT
servers:
  - url: https://api.intercom.io
    description: The production API server
  - url: https://api.eu.intercom.io
    description: The european API server
  - url: https://api.au.intercom.io
    description: The australian API server
security:
  - bearerAuth: []
tags:
  - name: Contacts
    description: Everything about your contacts
paths:
  /contacts/search:
    post:
      summary: Search contacts
      parameters:
        - name: Intercom-Version
          in: header
          schema:
            $ref: '#/components/schemas/intercom_version'
      tags:
        - Contacts
      operationId: SearchContacts
      description: |-
        You can search for multiple contacts by the value of their attributes in order to fetch exactly who you want.

        To search for contacts, you need to send a `POST` request to `https://api.intercom.io/contacts/search`.

        This will accept a query object in the body which will define your filters in order to search for contacts.

        **Optimizing search queries**

        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 `50` 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.

        ### Merged Contacts

        Contacts that have been merged (via POST /contacts/merge) are excluded from search results. If a contact was recently merged into another, it will no longer appear in queries filtered by `updated_at` or any other field. Only the target contact from the merge remains searchable.

        ### Contact Creation Delay

        If a contact has recently been created, there is a possibility that it will not yet be available when searching. This means that it may not appear in the response. This delay can take a few minutes. If you need to be instantly notified it is recommended to use webhooks and iterate to see if they match your search filters.

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

        ### Searching for Timestamp Fields

        Timestamp fields (`created_at`, `updated_at` etc.) and Date custom attributes are matched by calendar day. Sub-day precision (hour, minute, second) is not supported.

        The day boundary uses **your workspace's timezone**, so the same query can return different results on two workspaces in different timezones.

        Because the value is truncated to a day:

        - `=` matches the whole day.
        - `>` matches from the start of the _next_ day, not from the instant you passed.
        - `<` matches everything before the start of that day.

        The `!=`, `>=`, `<=`, `IN` and `NIN` operators are not supported on Date fields and return an error.

        **Example**, on a workspace set to UTC. Searching for `created_at` greater than `1577869200` (January 1st, 2020 9:00 AM UTC) truncates that value to `1577836800` (January 1st, 2020 12:00 AM UTC). Because `>` starts at the next day, the results begin from January 2nd, 2020 12:00 AM UTC - not from 9:00 AM on January 1st. On a workspace in another timezone, the boundaries fall on that timezone's midnight instead.

        To get contacts created on January 1st, 2020, search for `created_at` equal to `1577836800`.

        Only search queries behave this way. Responses still carry the full UNIX timestamp, and sorting uses the full value.

        ### Accepted Fields

        Most key listed as part of the Contacts Model are searchable, whether writeable or not. 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 `"foorbar"`).

        | Field | Type |
        | --- | --- |
        | id | String |
        | role | StringAccepts user or lead |
        | name | String |
        | avatar | String |
        | owner_id | Integer |
        | email | String |
        | email_domain | String |
        | phone | String |
        | external_id | String |
        | created_at | Date (Unix timestamp in seconds) |
        | signed_up_at | Date (Unix timestamp in seconds) |
        | updated_at | Date (Unix timestamp in seconds) |
        | last_seen_at | Date (Unix timestamp in seconds) |
        | last_contacted_at | Date (Unix timestamp in seconds) |
        | last_replied_at | Date (Unix timestamp in seconds) |
        | last_email_opened_at | Date (Unix timestamp in seconds) |
        | last_email_clicked_at | Date (Unix timestamp in seconds) |
        | language_override | String |
        | browser | String |
        | browser_language | String |
        | os | String |
        | location.country | String |
        | location.region | String |
        | location.city | String |
        | unsubscribed_from_emails | Boolean |
        | marked_email_as_spam | Boolean |
        | has_hard_bounced | Boolean |
        | ios_last_seen_at | Date (Unix timestamp in seconds) |
        | ios_app_version | String |
        | ios_device | String |
        | ios_app_device | String |
        | ios_os_version | String |
        | ios_app_name | String |
        | ios_sdk_version | String |
        | android_last_seen_at | Date (Unix timestamp in seconds) |
        | android_app_version | String |
        | android_device | String |
        | android_app_name | String |
        | andoid_sdk_version | String |
        | segment_id | String |
        | tag_id | String |
        | custom_attributes.{attribute_name} | String |

        ### Accepted Operators

        **Operators not supported on Date fields**

        Date fields (`created_at`, `updated_at`, and any Date custom attribute) do not support the `!=`, `>=`, or `<=` operators. Using them returns an error.

        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 (`"="`). Which operators are valid depends on the field's type - see the "Valid Types" column below. Searching by `tag_id` supports only the `=` and `!=` operators.

        | Operator | Valid Types | Description |
        | --- | --- | --- |
        | = | All | Equals |
        | != | All except Date | Doesn't Equal |
        | IN | All except Date and tag_id | InShortcut for `OR` queriesValues must be in Array |
        | NIN | All except Date and tag_id | Not InShortcut for `OR !` queriesValues must be in Array |
        | > | IntegerDate | Greater thanOn Date fields, matches from the start of the next day |
        | < | IntegerDate | Lower thanOn Date fields, matches before the start of the day |
        | >= | Integer | Greater than or equal toNot supported on Date fields |
        | <= | Integer | Lower than or equal toNot supported on Date fields |
        | ~ | String | Contains |
        | !~ | String | Doesn't Contain |
        | ^ | String | Starts With |
        | $ | String | Ends With |
      responses:
        '200':
          description: successful
          content:
            application/json:
              examples:
                successful:
                  value:
                    type: list
                    data: []
                    total_count: 0
                    pages:
                      type: pages
                      page: 1
                      per_page: 5
                      total_pages: 0
              schema:
                $ref: '#/components/schemas/contact_list'
        '401':
          description: Unauthorized
          content:
            application/json:
              examples:
                Unauthorized:
                  value:
                    type: error.list
                    request_id: 48002408-749d-46b2-8781-749f08e4ecc5
                    errors:
                      - code: unauthorized
                        message: Access Token Invalid
              schema:
                $ref: '#/components/schemas/error'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/search_request'
            examples:
              successful:
                summary: successful
                value:
                  query:
                    operator: AND
                    value:
                      - field: created_at
                        operator: '>'
                        value: '1306054154'
                  pagination:
                    per_page: 5
components:
  schemas:
    contact:
      title: Contact
      type: object
      x-tags:
        - Contacts
      x-fern-sdk-group-name: contacts
      description: Contacts represent your leads and users in Intercom.
      properties:
        type:
          type: string
          description: The type of object.
          example: contact
        id:
          type: string
          description: The unique identifier for the contact which is given by Intercom.
          example: 5ba682d23d7cf92bef87bfd4
        external_id:
          type: string
          nullable: true
          description: The unique identifier for the contact which is provided by the Client.
          example: f3b87a2e09d514c6c2e79b9a
        workspace_id:
          type: string
          description: The id of the workspace which the contact belongs to.
          example: ecahpwf5
        role:
          type: string
          description: The role of the contact.
          example: user
        email:
          type: string
          description: The contact's email.
          example: joe@example.com
        email_domain:
          type: string
          description: The contact's email domain.
          example: example.com
        phone:
          type: string
          nullable: true
          description: The contacts phone.
          example: '+1123456789'
        name:
          type: string
          nullable: true
          description: The contacts name.
          example: John Doe
        owner_id:
          type: integer
          nullable: true
          description: The id of an admin that has been assigned account ownership of the contact.
          example: 123
        has_hard_bounced:
          type: boolean
          description: Whether the contact has had an email sent to them hard bounce.
          example: true
        marked_email_as_spam:
          type: boolean
          description: Whether the contact has marked an email sent to them as spam.
          example: true
        unsubscribed_from_emails:
          type: boolean
          description: Whether the contact is unsubscribed from emails.
          example: true
        created_at:
          type: integer
          format: date-time
          description: (Unix timestamp in seconds) The time when the contact was created.
          example: 1571672154
        updated_at:
          type: integer
          format: date-time
          description: (Unix timestamp in seconds) The time when the contact was last updated.
          example: 1571672154
        signed_up_at:
          type: integer
          format: date-time
          nullable: true
          description: (Unix timestamp in seconds) The time specified for when a contact signed up.
          example: 1571672154
        last_seen_at:
          type: integer
          format: date-time
          nullable: true
          description: (Unix timestamp in seconds) The time when the contact was last seen (either where the Intercom Messenger was installed or when specified manually).
          example: 1571672154
        last_replied_at:
          type: integer
          format: date-time
          nullable: true
          description: (Unix timestamp in seconds) The time when the contact last messaged in.
          example: 1571672154
        last_contacted_at:
          type: integer
          format: date-time
          nullable: true
          description: (Unix timestamp in seconds) The time when the contact was last messaged.
          example: 1571672154
        last_email_opened_at:
          type: integer
          format: date-time
          nullable: true
          description: (Unix timestamp in seconds) The time when the contact last opened an email.
          example: 1571672154
        last_email_clicked_at:
          type: integer
          format: date-time
          nullable: true
          description: (Unix timestamp in seconds) The time when the contact last clicked a link in an email.
          example: 1571672154
        language_override:
          type: string
          nullable: true
          description: A preferred language setting for the contact, used by the Intercom Messenger even if their browser settings change.
          example: en
        browser:
          type: string
          nullable: true
          description: The name of the browser which the contact is using.
          example: Chrome
        browser_version:
          type: string
          nullable: true
          description: The version of the browser which the contact is using.
          example: 80.0.3987.132
        browser_language:
          type: string
          nullable: true
          description: The language set by the browser which the contact is using.
          example: en-US
        os:
          type: string
          nullable: true
          description: The operating system which the contact is using.
          example: Mac OS X
        android_app_name:
          type: string
          nullable: true
          description: The name of the Android app which the contact is using.
          example: Intercom
        android_app_version:
          type: string
          nullable: true
          description: The version of the Android app which the contact is using.
          example: 5.0.0
        android_device:
          type: string
          nullable: true
          description: The Android device which the contact is using.
          example: Pixel 3
        android_os_version:
          type: string
          nullable: true
          description: The version of the Android OS which the contact is using.
          example: '10'
        android_sdk_version:
          type: string
          nullable: true
          description: The version of the Android SDK which the contact is using.
          example: '28'
        android_last_seen_at:
          type: integer
          nullable: true
          format: date-time
          description: (Unix timestamp in seconds) The time when the contact was last seen on an Android device.
          example: 1571672154
        ios_app_name:
          type: string
          nullable: true
          description: The name of the iOS app which the contact is using.
          example: Intercom
        ios_app_version:
          type: string
          nullable: true
          description: The version of the iOS app which the contact is using.
          example: 5.0.0
        ios_device:
          type: string
          nullable: true
          description: The iOS device which the contact is using.
          example: iPhone 11
        ios_os_version:
          type: string
          nullable: true
          description: The version of iOS which the contact is using.
          example: 13.3.1
        ios_sdk_version:
          type: string
          nullable: true
          description: The version of the iOS SDK which the contact is using.
          example: 13.3.1
        ios_last_seen_at:
          type: integer
          nullable: true
          format: date-time
          description: (Unix timestamp in seconds) The last time the contact used the iOS app.
          example: 1571672154
        custom_attributes:
          type: object
          description: The custom attributes which are set for the contact.
        avatar:
          type: object
          nullable: true
          properties:
            type:
              type: string
              description: The type of object
              example: avatar
            image_url:
              type: string
              format: uri
              nullable: true
              description: An image URL containing the avatar of a contact.
              example: https://example.org/128Wash.jpg
        tags:
          $ref: '#/components/schemas/contact_tags'
        notes:
          $ref: '#/components/schemas/contact_notes'
        companies:
          $ref: '#/components/schemas/contact_companies'
        location:
          $ref: '#/components/schemas/contact_location'
        social_profiles:
          $ref: '#/components/schemas/contact_social_profiles'
    contact_companies:
      title: Contact companies
      type: object
      nullable: false
      description: An object containing companies meta data about the companies that a contact has. Up to 10 will be displayed here. Use the url to get more.
      properties:
        data:
          type: array
          description: An array of company data objects attached to the contact.
          items:
            $ref: '#/components/schemas/company_data'
        url:
          type: string
          format: uri
          description: Url to get more company resources for this contact
          example: /contacts/5ba682d23d7cf92bef87bfd4/companies
        total_count:
          type: integer
          description: Int representing the total number of companyies attached to this contact
          example: 100
        has_more:
          type: boolean
          description: Whether there's more Addressable Objects to be viewed. If true, use the url to view all
          example: true
    contact_list:
      title: Contact List
      type: object
      description: Contacts are your users in Intercom.
      properties:
        type:
          type: string
          description: Always list
          enum:
            - list
          example: list
        data:
          type: array
          description: The list of contact objects
          items:
            $ref: '#/components/schemas/contact'
        total_count:
          type: integer
          description: A count of the total number of objects.
          example: 100
        pages:
          $ref: '#/components/schemas/cursor_pages'
    contact_location:
      title: Contact Location
      type: object
      nullable: false
      description: An object containing location meta data about a Intercom contact.
      properties:
        type:
          type: string
          nullable: true
          description: Always location
          example: location
        country:
          type: string
          nullable: true
          description: The country that the contact is located in
          example: Ireland
        region:
          type: string
          nullable: true
          description: The overal region that the contact is located in
          example: Dublin
        city:
          type: string
          nullable: true
          description: The city that the contact is located in
          example: Dublin
    contact_notes:
      title: Contact notes
      type: object
      nullable: false
      description: An object containing notes meta data about the notes that a contact has. Up to 10 will be displayed here. Use the url to get more.
      properties:
        data:
          type: array
          description: This object represents the notes attached to a contact.
          items:
            $ref: '#/components/schemas/addressable_list'
        url:
          type: string
          format: uri
          description: Url to get more company resources for this contact
          example: /contacts/5ba682d23d7cf92bef87bfd4/notes
        total_count:
          type: integer
          description: Int representing the total number of companyies attached to this contact
          example: 100
        has_more:
          type: boolean
          description: Whether there's more Addressable Objects to be viewed. If true, use the url to view all
          example: true
    contact_social_profiles:
      title: Social Profile
      type: object
      nullable: false
      description: An object containing social profiles that a contact has.
      properties:
        data:
          type: array
          description: A list of social profiles objects associated with the contact.
          items:
            $ref: '#/components/schemas/social_profile'
    contact_tags:
      title: Contact Tags
      type: object
      nullable: true
      description: An object containing tags meta data about the tags that a contact has. Up to 10 will be displayed here. Use the url to get more.
      properties:
        data:
          type: array
          description: This object represents the tags attached to a contact.
          items:
            $ref: '#/components/schemas/addressable_list'
        url:
          type: string
          format: uri
          description: url to get more tag resources for this contact
          example: /contacts/5ba682d23d7cf92bef87bfd4/tags
        total_count:
          type: integer
          description: Int representing the total number of tags attached to this contact
          example: 100
        has_more:
          type: boolean
          description: Whether there's more Addressable Objects to be viewed. If true, use the url to view all
          example: true
    cursor_pages:
      title: Cursor based pages
      type: object
      description: |
        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.
      nullable: true
      properties:
        type:
          type: string
          description: the type of object `pages`.
          example: pages
          enum:
            - pages
        page:
          type: integer
          description: The current page
          example: 1
        next:
          $ref: '#/components/schemas/starting_after_paging'
        per_page:
          type: integer
          description: Number of results per page
          example: 2
        total_pages:
          type: integer
          description: Total number of pages
          example: 13
    error:
      type: object
      title: Error
      description: The API will return an Error List for a failed request, which will contain one or more Error objects.
      properties:
        type:
          type: string
          description: The type is error.list
          example: error.list
        request_id:
          type: string
          nullable: true
          format: uuid
          description: ''
          example: f93ecfa8-d08a-4325-8694-89aeb89c8f85
        errors:
          type: array
          description: An array of one or more error objects
          items:
            properties:
              code:
                type: string
                description: A string indicating the kind of error, used to further qualify the HTTP response code
                example: unauthorized
              message:
                type: string
                nullable: true
                description: Optional. Human readable description of the error.
                example: Access Token Invalid
              field:
                type: string
                nullable: true
                description: Optional. Used to identify a particular field or query parameter that was in error.
                example: email
            required:
              - code
      required:
        - type
        - errors
    intercom_version:
      description: Intercom API version.</br>By default, it's equal to the version set in the app package.
      type: string
      example: '2.12'
      default: '2.12'
      enum:
        - '1.0'
        - '1.1'
        - '1.2'
        - '1.3'
        - '1.4'
        - '2.0'
        - '2.1'
        - '2.2'
        - '2.3'
        - '2.4'
        - '2.5'
        - '2.6'
        - '2.7'
        - '2.8'
        - '2.9'
        - '2.10'
        - '2.11'
        - '2.12'
        - Preview
    multiple_filter_search_request:
      title: Multiple Filter Search Request
      description: Search using Intercoms Search APIs with more than one filter.
      type: object
      properties:
        operator:
          type: string
          enum:
            - AND
            - OR
          description: An operator to allow boolean inspection between multiple fields.
          example: AND
        value:
          oneOf:
            - type: array
              description: Add mutiple filters.
              title: multiple filter search request
              items:
                $ref: '#/components/schemas/multiple_filter_search_request'
            - type: array
              description: Add a single filter field.
              title: single filter search request
              items:
                $ref: '#/components/schemas/single_filter_search_request'
    search_request:
      description: Search using Intercoms Search APIs.
      type: object
      title: Search data
      properties:
        query:
          oneOf:
            - $ref: '#/components/schemas/single_filter_search_request'
              title: Single filter search request
            - $ref: '#/components/schemas/multiple_filter_search_request'
              title: multiple filter search request
        pagination:
          $ref: '#/components/schemas/starting_after_paging'
      required:
        - query
    single_filter_search_request:
      title: Single Filter Search Request
      description: Search using Intercoms Search APIs with a single filter.
      type: object
      properties:
        field:
          type: string
          description: The accepted field that you want to search on.
          example: created_at
        operator:
          type: string
          enum:
            - '='
            - '!='
            - IN
            - NIN
            - <
            - <=
            - '>'
            - '>='
            - '~'
            - '!~'
            - ^
            - $
          description: |-
            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`, `<`, `>`, `<=`, `>=`
            - `date` fields (all standard timestamp attributes and date custom attributes): `=`, `<`, `>` only. `!=`, `<=`, `>=`, `IN`, and `NIN` are not supported and return an error.
          example: '>'
        value:
          oneOf:
            - type: string
            - type: integer
            - type: array
              items:
                oneOf:
                  - type: string
                  - type: integer
          description: The value that you want to search on.
          example: '73732934'
          nullable: true
    starting_after_paging:
      title: 'Pagination: Starting After'
      type: object
      nullable: true
      properties:
        per_page:
          type: integer
          description: The number of results to fetch per page.
          example: 2
        starting_after:
          type: string
          description: The cursor to use in the next request to get the next page of results.
          nullable: true
          example: your-cursor-from-response
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
```
