> For a complete page index, fetch https://developer.close.com/llms.txt

# Search objects with filters

POST https://api.close.com/api/v1/data/search/
Content-Type: application/json

Find Leads, Contacts, Opportunities, Activities, Tasks and other objects matching any combination of filters. This is the API behind the filters on the Leads, Contacts and Opportunities pages in Close, and the query language used by Smart Views (`s_query`) and bulk actions.

Searching doesn't change any data.

### Building a query

A query is a tree of objects, each with a `type`:

1. Start with an `and` query.
2. Add an `object_type` query for the type of objects you want, e.g. `{"type": "object_type", "object_type": "lead"}`.
3. Add a `field_condition` query for each filter. It combines a `field` with a `condition`:
   * Built-in fields are `regular_field`s. Their `object_type` must be the type you're searching for, e.g. `title` on `contact`.
   * Custom fields are referenced by ID as `custom_field`s. List them with the custom field endpoints, e.g. `GET /custom_field/lead/`.
   * The condition depends on the field's type: `text` for text, `term` for choices and fixed values, `reference` for IDs (statuses, users, ...), `number_range` for numbers, `moment_range` for dates. See `FieldCondition`.
4. To filter by related objects, use `has_related`. For example, Leads with a Contact whose title contains "CEO", or Contacts whose Lead is in a status.

Use `or` for alternatives and set `negate: true` on any query to exclude what it matches.

You can also build a filter on the Leads, Contacts or Opportunities page in Close and copy its JSON with **Copy Filters** in the page's menu.

### Dates

Relative dates are resolved when the search runs. For example, "in the last 30 days" is a `moment_range` condition starting at an `offset` moment of 30 days in the past. Dates without a timezone use the timezone from the `X-TZ-Name` header (an IANA name like `America/New_York`), or UTC.

### Results

Results only contain each object's `id` and `__object_type` unless you list the fields you want in `_fields`, e.g. `{"lead": ["id", "display_name"]}`. Field names are the same as in the object type's own endpoint.

### Pagination and limits

* Each page has up to `_limit` results (at most 200). Pass the response's `cursor` to get the next page. The last page has a `null` cursor. Cursors expire after 30 seconds.
* Pagination stops after 10,000 results. To go through more, split the search, e.g. by `date_created` ranges.
* Sort by a field that rarely changes, like `date_created`, while paginating.
* `results_limit` caps the total number of results. Set it to `0` with `include_counts: true` to only count matches.
* The request body can be at most 50 KB. Overly complex queries are rejected.

Reference: https://developer.close.com/api/resources/advanced-filtering/search

## Authentication

- `Authorization` header (basic auth, required) — Use your API key as the username and leave the password empty.
- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/json)

This endpoint expects a DataSearchRequest.

- `_fields` (map from string to list of string, optional, default: {}) — Fields to return for each object type. The field names are the same as in the object type's own endpoint, e.g. `{"lead": ["id", "display_name"]}`. Custom fields use `custom.cf_abc123`. Without it, results only contain `id` and `__object_type`.
- `_limit` (integer, optional, default: 10) — Number of results per page.
- `cursor` (string, optional, nullable) — The `cursor` from the previous page's response. Cursors expire after 30 seconds.
- `include_counts` (boolean, optional, default: false) — Whether to include the number of matches in `count`.
- `query` (SearchQuery, optional) — The query objects must match. Start with an `and` query that contains an `object_type` query for the type of objects to return.
- `results_limit` (integer, optional, nullable) — Maximum number of results across all pages, e.g. to act only on the first 100 matches. Use `0` with `include_counts` to only count matches.
- `sort` (list of SearchSort, optional, default: []) — Fields to sort results by. When paginating, sort by a field that rarely changes, like `date_created`, so no results are skipped.

## Response

### 200

Successful response

- `cursor` (string, required, nullable) — Pass it as `cursor` to get the next page. `null` on the last page.
- `data` (list of SearchResult, required) — The matching objects on this page.
- `count` (SearchResultCount, optional) — Number of matches. Only included with `include_counts`.

## Errors

### 400 Bad Request Error

Bad request

- `any`

### 401 Unauthorized Error

Unauthorized

- `any`

### 403 Forbidden Error

The user can't access the organization.

- `any`

### 404 Not Found Error

Not found

- `any`

### 429 Too Many Requests Error

Too many requests.

- `any`

## Types

### SearchQuery

A search query. Queries are distinguished by their `type`. Combine queries with `and` and `or`, and use `negate` on any query to exclude what it matches.

- `type`: `and` (AndQuery)
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
  - `queries` (list of SearchQuery, optional, default: []) — The queries that must all match.
- `type`: `any_of_saved_search` (AnyOfSavedSearchQuery)
  - `saved_search_ids` (list of string, required) — IDs of the Smart Views. At most 10.
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
- `type`: `field_condition` (FieldConditionQuery)
  - `condition` (FieldCondition, required) — The condition the field value must satisfy.
  - `field` (SearchField, required) — The field to check.
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
- `type`: `has_related` (HasRelatedQuery)
  - `related_object_type` (enum, required) — The type of the related objects.
    - Allowed values: `activity.call`, `activity.created`, `activity.custom_activity`, `activity.email`, `activity.email_thread`, `activity.form_submission`, `activity.import_update`, `activity.lead_merge`, `activity.lead_status_change`, `activity.meeting`, `activity.note`, `activity.opportunity_status_change`, `activity.sms`, `activity.task_completed`, `activity.whatsapp_message`, `contact`, `custom_fields.contact`, `custom_fields.lead`, `custom_fields.opportunity`, `email_template`, `sms_template`, `lead`, `opportunity`, `saved_search`, `status.lead`, `status.opportunity`, `task.answered_detached_call`, `task.email_followup`, `task.incoming_email`, `task.lead_suggestion_incoming_email`, `task.incoming_sms`, `task.incoming_whatsapp_message`, `task.lead`, `task.outbound_call`, `task.draft_email`, `task.draft_sms`, `task.missed_call`, `task.opportunity_due`, `task.opportunities_awaiting_action`, `task.voicemail`, `sequence_subscription`, `subscription_history`, `custom_object`, `lead_file`, `comment_thread`, `comment`, `lead_summary`, `agent_call_grade`, `address`, `contact_email`, `contact_phone`, `contact_url`
  - `this_object_type` (enum, required) — The type of the objects being filtered.
    - Allowed values: `activity.call`, `activity.created`, `activity.custom_activity`, `activity.email`, `activity.email_thread`, `activity.form_submission`, `activity.import_update`, `activity.lead_merge`, `activity.lead_status_change`, `activity.meeting`, `activity.note`, `activity.opportunity_status_change`, `activity.sms`, `activity.task_completed`, `activity.whatsapp_message`, `contact`, `custom_fields.contact`, `custom_fields.lead`, `custom_fields.opportunity`, `email_template`, `sms_template`, `lead`, `opportunity`, `saved_search`, `status.lead`, `status.opportunity`, `task.answered_detached_call`, `task.email_followup`, `task.incoming_email`, `task.lead_suggestion_incoming_email`, `task.incoming_sms`, `task.incoming_whatsapp_message`, `task.lead`, `task.outbound_call`, `task.draft_email`, `task.draft_sms`, `task.missed_call`, `task.opportunity_due`, `task.opportunities_awaiting_action`, `task.voicemail`, `sequence_subscription`, `subscription_history`, `custom_object`, `lead_file`, `comment_thread`, `comment`, `lead_summary`, `agent_call_grade`, `address`, `contact_email`, `contact_phone`, `contact_url`
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
  - `related_query` (SearchQuery, optional) — The query a related object must match. Fields in it belong to the related object type.
- `type`: `id` (IdQuery)
  - `value` (string, required) — The object ID, e.g. `lead_abc123`.
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
- `type`: `in_status` (InStatusQuery)
  - `status_ids` (list of string, required) — IDs of Lead or Opportunity statuses.
  - `before` (Moment, optional) — End of the period (exclusive).
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
  - `on_or_after` (Moment, optional) — Start of the period (inclusive).
- `type`: `match_all` (MatchAllQuery)
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
- `type`: `object_type` (ObjectTypeQuery)
  - `object_type` (enum, required) — The object type.
    - Allowed values: `activity.call`, `activity.created`, `activity.custom_activity`, `activity.email`, `activity.email_thread`, `activity.form_submission`, `activity.import_update`, `activity.lead_merge`, `activity.lead_status_change`, `activity.meeting`, `activity.note`, `activity.opportunity_status_change`, `activity.sms`, `activity.task_completed`, `activity.whatsapp_message`, `contact`, `custom_fields.contact`, `custom_fields.lead`, `custom_fields.opportunity`, `email_template`, `sms_template`, `lead`, `opportunity`, `saved_search`, `status.lead`, `status.opportunity`, `task.answered_detached_call`, `task.email_followup`, `task.incoming_email`, `task.lead_suggestion_incoming_email`, `task.incoming_sms`, `task.incoming_whatsapp_message`, `task.lead`, `task.outbound_call`, `task.draft_email`, `task.draft_sms`, `task.missed_call`, `task.opportunity_due`, `task.opportunities_awaiting_action`, `task.voicemail`, `sequence_subscription`, `subscription_history`, `custom_object`, `lead_file`, `comment_thread`, `comment`, `lead_summary`, `agent_call_grade`, `address`, `contact_email`, `contact_phone`, `contact_url`
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
- `type`: `or` (OrQuery)
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
  - `queries` (list of SearchQuery, optional, default: []) — The queries of which at least one must match.
- `type`: `saved_search` (SavedSearchQuery)
  - `saved_search_id` (string, required) — ID of the Smart View, e.g. `save_abc123`.
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.
- `type`: `text` (TextQuery)
  - `mode` (enum, required) — How to match the text.
    - Allowed values: `full_words`, `phrase`, `beginning_of_words`, `exact_value`
  - `value` (string, required) — The text to look for.
  - `negate` (boolean, optional, default: false) — Match objects that do NOT match this query instead.

### SearchSort

A field to sort results by.

- `direction` (enum, required) — The sort direction.
  - Allowed values: `asc`, `desc`
- `field` (SearchField, required) — The field to sort by. Only number, date and text fields of the returned object type can be used.

### SearchResult

A matching object. Contains the fields requested in `_fields` for its object type, in the same format as the object type's own endpoint, including custom fields as `custom.cf_abc123` keys.

- `__object_type` (enum, required) — The type of the object.
  - Allowed values: `activity.call`, `activity.created`, `activity.custom_activity`, `activity.email`, `activity.email_thread`, `activity.form_submission`, `activity.import_update`, `activity.lead_merge`, `activity.lead_status_change`, `activity.meeting`, `activity.note`, `activity.opportunity_status_change`, `activity.sms`, `activity.task_completed`, `activity.whatsapp_message`, `contact`, `custom_fields.contact`, `custom_fields.lead`, `custom_fields.opportunity`, `email_template`, `sms_template`, `lead`, `opportunity`, `saved_search`, `status.lead`, `status.opportunity`, `task.answered_detached_call`, `task.email_followup`, `task.incoming_email`, `task.lead_suggestion_incoming_email`, `task.incoming_sms`, `task.incoming_whatsapp_message`, `task.lead`, `task.outbound_call`, `task.draft_email`, `task.draft_sms`, `task.missed_call`, `task.opportunity_due`, `task.opportunities_awaiting_action`, `task.voicemail`, `sequence_subscription`, `subscription_history`, `custom_object`, `lead_file`, `comment_thread`, `comment`, `lead_summary`, `agent_call_grade`, `address`, `contact_email`, `contact_phone`, `contact_url`
- `id` (string, optional) — ID of the object, e.g. `lead_abc123`. When requesting specific `_fields`, include `id` to get it.

### SearchResultCount

- `limited` (integer, required) — Number of matching objects available through pagination, i.e. `total` capped at `results_limit`.
- `total` (integer, required) — Number of objects matching the query.

### FieldCondition

A condition a field value must satisfy. Which conditions apply depends on the field's type: - Text, email, phone and URL fields: `text`, `multiple_text`. - Fields with a fixed set of values and choice custom fields: `term`. - References to other objects (IDs): `reference`. For user fields also `current_user`. - Numbers: `number_range`, `number`, `multiple_numbers`. - Durations: `duration_range`. - Dates and datetimes: `moment_range`, `predefined_relative_date_range`, `fixed_date_range`, `exact_moment`. - Booleans: `boolean`. - Timezones: `timezone_name`, `local_time`. - Any field: `exists`.

- `type`: `boolean` (BooleanCondition)
  - `value` (boolean, required) — The value to match.
- `type`: `current_user` (CurrentUserCondition)
- `type`: `duration_range` (DurationRangeCondition)
  - `gt` (Duration, optional) — Greater than.
  - `gte` (Duration, optional) — Greater than or equal.
  - `lt` (Duration, optional) — Less than.
  - `lte` (Duration, optional) — Less than or equal.
- `type`: `exact_moment` (ExactMomentCondition)
  - `at` (Moment, required) — The moment to match.
- `type`: `exists` (ExistsCondition)
- `type`: `fixed_date_range` (DateRangeCondition)
  - `gt` (date, optional) — Greater than.
  - `gte` (date, optional) — Greater than or equal.
  - `lt` (date, optional) — Less than.
  - `lte` (date, optional) — Less than or equal.
- `type`: `local_time` (LocalTimeCondition)
  - `before` (string, optional) — End of the range (exclusive), e.g. `17:00`. Defaults to the end of the day.
  - `on_or_after` (string, optional, default: 00:00:00) — Start of the range (inclusive), e.g. `09:00`. Defaults to midnight.
- `type`: `moment_range` (MomentRangeCondition)
  - `before` (Moment, optional) — End of the range (exclusive).
  - `on_or_after` (Moment, optional) — Start of the range (inclusive).
- `type`: `multiple_numbers` (MultipleNumbersCondition)
  - `values` (list of MultipleNumbersConditionValuesItems, required) — Matches any of these values. At most 800.
- `type`: `multiple_text` (MultipleTextCondition)
  - `mode` (enum, required) — How to match the texts.
    - Allowed values: `full_words`, `phrase`, `beginning_of_words`, `exact_value`
  - `values` (list of string, required) — Matches any of these texts. At most 800, each at most 200 characters long.
- `type`: `number` (NumberCondition)
  - `value` (NumberConditionValue, required) — The value to match.
- `type`: `number_range` (NumberRangeCondition)
  - `gt` (NumberRangeConditionGt, optional) — Greater than.
  - `gte` (NumberRangeConditionGte, optional) — Greater than or equal.
  - `lt` (NumberRangeConditionLt, optional) — Less than.
  - `lte` (NumberRangeConditionLte, optional) — Less than or equal.
- `type`: `predefined_relative_date_range` (RelativeDateRangeCondition)
  - `value` (enum, required) — The predefined relative range.
    - Allowed values: `yesterday`, `last-week`, `last-month`, `last-quarter`, `last-year`, `today`, `this-week`, `this-month`, `this-quarter`, `this-year`, `tomorrow`, `next-week`, `next-month`, `next-quarter`, `next-year`, `closest-monday`, `closest-tuesday`, `closest-wednesday`, `closest-thursday`, `closest-friday`, `closest-saturday`, `closest-sunday`, `all-time`
- `type`: `reference` (ReferenceCondition)
  - `object_ids` (list of string, required) — IDs of the referenced objects. Matches any of them.
  - `reference_type` (enum, required) — The type of the referenced objects.
    - Allowed values: `activity.call`, `activity.created`, `activity.custom_activity`, `activity.email`, `activity.email_thread`, `activity.form_submission`, `activity.import_update`, `activity.lead_merge`, `activity.lead_status_change`, `activity.meeting`, `activity.note`, `activity.opportunity_status_change`, `activity.sms`, `activity.task_completed`, `activity.whatsapp_message`, `contact`, `custom_fields.contact`, `custom_fields.lead`, `custom_fields.opportunity`, `email_template`, `sms_template`, `lead`, `opportunity`, `saved_search`, `status.lead`, `status.opportunity`, `task.answered_detached_call`, `task.email_followup`, `task.incoming_email`, `task.lead_suggestion_incoming_email`, `task.incoming_sms`, `task.incoming_whatsapp_message`, `task.lead`, `task.outbound_call`, `task.draft_email`, `task.draft_sms`, `task.missed_call`, `task.opportunity_due`, `task.opportunities_awaiting_action`, `task.voicemail`, `sequence_subscription`, `subscription_history`, `custom_object`, `lead_file`, `comment_thread`, `comment`, `lead_summary`, `agent_call_grade`, `agent_config`, `any_agent`, `user`, `group`, `user_or_group`, `user_or_agent`, `user_or_any_agent`, `user_or_group_or_agent`, `user_or_group_or_any_agent`, `sequence`, `sequence_step`, `pipeline`, `custom_activity_type`, `bulk_action.email`, `bulk_action.edit`, `bulk_action.delete`, `bulk_action.sequence_subscription`, `connected_account`, `dialer`, `import`, `membership`, `custom_object_type`, `phone_number`, `custom_fields.activity`, `outcome`, `form`, `form_configuration`, `conversation_type`
- `type`: `term` (TermCondition)
  - `values` (list of string, required) — Matches any of these values.
- `type`: `text` (TextCondition)
  - `mode` (enum, required) — How to match the text.
    - Allowed values: `full_words`, `phrase`, `beginning_of_words`, `exact_value`
  - `value` (string, required) — The text to look for.
- `type`: `timezone_name` (TimezoneNameCondition)
  - `values` (list of string, required) — IANA timezone names, e.g. `America/New_York`.

### SearchField

A field to filter or sort by.

- `type`: `custom_field` (CustomSearchField)
  - `custom_field_id` (string, required) — ID of the custom field, e.g. `cf_abc123`.
- `type`: `form_field` (FormFieldSearchField)
  - `form_field_id` (string, required) — ID of the form field.
- `type`: `regular_field` (RegularSearchField)
  - `field_name` (string, required) — Name of the field, e.g. `display_name` on `lead` or `title` on `contact`.
  - `object_type` (enum, required) — The object type the field belongs to. It must match the object type being filtered, use a `has_related` query to filter by fields of related objects.
    - Allowed values: `activity.call`, `activity.created`, `activity.custom_activity`, `activity.email`, `activity.email_thread`, `activity.form_submission`, `activity.import_update`, `activity.lead_merge`, `activity.lead_status_change`, `activity.meeting`, `activity.note`, `activity.opportunity_status_change`, `activity.sms`, `activity.task_completed`, `activity.whatsapp_message`, `contact`, `custom_fields.contact`, `custom_fields.lead`, `custom_fields.opportunity`, `email_template`, `sms_template`, `lead`, `opportunity`, `saved_search`, `status.lead`, `status.opportunity`, `task.answered_detached_call`, `task.email_followup`, `task.incoming_email`, `task.lead_suggestion_incoming_email`, `task.incoming_sms`, `task.incoming_whatsapp_message`, `task.lead`, `task.outbound_call`, `task.draft_email`, `task.draft_sms`, `task.missed_call`, `task.opportunity_due`, `task.opportunities_awaiting_action`, `task.voicemail`, `sequence_subscription`, `subscription_history`, `custom_object`, `lead_file`, `comment_thread`, `comment`, `lead_summary`, `agent_call_grade`, `address`, `contact_email`, `contact_phone`, `contact_url`

### Moment

A point in time, evaluated when the search runs.

- `type`: `fixed_local` (FixedLocalMoment)
  - `value` (datetime, required) — ISO 8601 datetime without a timezone, e.g. `2024-01-31T14:00:00`.
- `type`: `fixed_local_date` (FixedLocalDateMoment)
  - `value` (date, required) — ISO 8601 date, e.g. `2024-01-31`.
  - `which` (enum, required) — Whether to use the start or the end of the day.
    - Allowed values: `start`, `end`
- `type`: `fixed_utc` (FixedUTCMoment)
  - `value` (datetime, required) — ISO 8601 datetime, e.g. `2024-01-31T14:00:00Z`. A value without a timezone is treated as UTC. Other timezones are rejected.
- `type`: `now` (NowMoment)
- `type`: `offset` (OffsetMoment)
  - `direction` (enum, required) — Whether to shift into the past or the future.
    - Allowed values: `future`, `past`
  - `offset` (Duration, required) — How far to shift the moment.
  - `moment` (Moment, optional) — The moment to shift. Defaults to now.
  - `which_day_end` (enum, optional) — If the offset includes days, weeks, months or years, the moment is first moved to the start or end of its day.
    - Allowed values: `start`, `end`
- `type`: `start_end_of_period` (StartEndOfPeriodMoment)
  - `period` (enum, required) — The calendar period.
    - Allowed values: `second`, `minute`, `hour`, `day`, `week`, `month`, `quarter`, `year`
  - `which` (enum, required) — Whether to use the start or the end of the period.
    - Allowed values: `start`, `end`
  - `moment` (Moment, optional) — The moment whose period is used. Defaults to now.
- `type`: `start_end_of_predefined_relative_period` (StartEndOfPredefinedRelativePeriodMoment)
  - `range` (enum, required) — The predefined relative range.
    - Allowed values: `yesterday`, `last-week`, `last-month`, `last-quarter`, `last-year`, `today`, `this-week`, `this-month`, `this-quarter`, `this-year`, `tomorrow`, `next-week`, `next-month`, `next-quarter`, `next-year`, `closest-monday`, `closest-tuesday`, `closest-wednesday`, `closest-thursday`, `closest-friday`, `closest-saturday`, `closest-sunday`, `all-time`
  - `which` (enum, required) — Whether to use the start or the end of the range.
    - Allowed values: `start`, `end`

### Duration

A calendar-aware duration. All given parts are added together.

- `days` (integer, optional, default: 0)
- `hours` (integer, optional, default: 0)
- `minutes` (integer, optional, default: 0)
- `months` (integer, optional, default: 0)
- `seconds` (integer, optional, default: 0)
- `weeks` (integer, optional, default: 0)
- `years` (integer, optional, default: 0)

### MultipleNumbersConditionValuesItems

- integer
- double

### NumberConditionValue

The value to match.

- integer
- double

### NumberRangeConditionGt

Greater than.

- integer
- double

### NumberRangeConditionGte

Greater than or equal.

- integer
- double

### NumberRangeConditionLt

Less than.

- integer
- double

### NumberRangeConditionLte

Less than or equal.

- integer
- double

## Examples

### Contacts with a title

**Request**

```json
{
  "_fields": {
    "contact": [
      "id",
      "lead_id",
      "name",
      "title"
    ]
  },
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "contact"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "text",
          "mode": "full_words",
          "value": "CEO"
        },
        "field": {
          "type": "regular_field",
          "field_name": "title",
          "object_type": "contact"
        }
      }
    ]
  }
}
```

**Response**

```json
{
  "cursor": null,
  "data": [
    {
      "__object_type": "contact",
      "id": "cont_PtENYt1P6sRWkcnqoGnIj6hcZammGPdVbTXJWqdTvpV",
      "lead_id": "lead_Wj0mVbjRrAhVeqOTnMHXdpcUBHAOPtmFbzoxK0U2Mn0",
      "name": "Lucille Bluth",
      "title": "CEO"
    },
    {
      "__object_type": "contact",
      "id": "cont_HjTcJFiNli2AKf5fioygQDVSpA9nJILI9SkKv3nBk0A",
      "lead_id": "lead_ViJkLOWx4ZOa9q3eIMuxbBtT1EuNrQhw6DQ0XDm6lxs",
      "name": "Steli Efti",
      "title": "CEO & Co-Founder"
    }
  ]
}
```

**SDK Code**

```python Contacts with a title
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = {
    "_fields": { "contact": ["id", "lead_id", "name", "title"] },
    "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "contact"
            },
            {
                "type": "field_condition",
                "condition": {
                    "type": "text",
                    "mode": "full_words",
                    "value": "CEO"
                },
                "field": {
                    "type": "regular_field",
                    "field_name": "title",
                    "object_type": "contact"
                }
            }
        ]
    }
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Contacts with a title
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"_fields":{"contact":["id","lead_id","name","title"]},"query":{"type":"and","queries":[{"type":"object_type","object_type":"contact"},{"type":"field_condition","condition":{"type":"text","mode":"full_words","value":"CEO"},"field":{"type":"regular_field","field_name":"title","object_type":"contact"}}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Contacts with a title
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"_fields\": {\n    \"contact\": [\n      \"id\",\n      \"lead_id\",\n      \"name\",\n      \"title\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"contact\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"text\",\n          \"mode\": \"full_words\",\n          \"value\": \"CEO\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"title\",\n          \"object_type\": \"contact\"\n        }\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Contacts with a title
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"_fields\": {\n    \"contact\": [\n      \"id\",\n      \"lead_id\",\n      \"name\",\n      \"title\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"contact\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"text\",\n          \"mode\": \"full_words\",\n          \"value\": \"CEO\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"title\",\n          \"object_type\": \"contact\"\n        }\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Contacts with a title
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"_fields\": {\n    \"contact\": [\n      \"id\",\n      \"lead_id\",\n      \"name\",\n      \"title\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"contact\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"text\",\n          \"mode\": \"full_words\",\n          \"value\": \"CEO\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"title\",\n          \"object_type\": \"contact\"\n        }\n      }\n    ]\n  }\n}")
  .asString();
```

```php Contacts with a title
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "_fields": {
    "contact": [
      "id",
      "lead_id",
      "name",
      "title"
    ]
  },
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "contact"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "text",
          "mode": "full_words",
          "value": "CEO"
        },
        "field": {
          "type": "regular_field",
          "field_name": "title",
          "object_type": "contact"
        }
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Contacts with a title
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"_fields\": {\n    \"contact\": [\n      \"id\",\n      \"lead_id\",\n      \"name\",\n      \"title\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"contact\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"text\",\n          \"mode\": \"full_words\",\n          \"value\": \"CEO\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"title\",\n          \"object_type\": \"contact\"\n        }\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Leads in a status, newest first

**Request**

```json
{
  "_fields": {
    "lead": [
      "display_name",
      "id",
      "status_label"
    ]
  },
  "_limit": 2,
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "reference",
          "object_ids": [
            "stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk"
          ],
          "reference_type": "status.lead"
        },
        "field": {
          "type": "regular_field",
          "field_name": "status_id",
          "object_type": "lead"
        }
      }
    ]
  },
  "sort": [
    {
      "direction": "desc",
      "field": {
        "type": "regular_field",
        "field_name": "date_created",
        "object_type": "lead"
      }
    }
  ]
}
```

**Response**

```json
{
  "cursor": "eyJza2lwIjoyfQ.ZxH1kg.1lTbZ8qz3cX0v8K0QO5O3oJm9yM",
  "data": [
    {
      "__object_type": "lead",
      "id": "lead_Wj0mVbjRrAhVeqOTnMHXdpcUBHAOPtmFbzoxK0U2Mn0",
      "display_name": "Bluth Company",
      "status_label": "Qualified"
    },
    {
      "__object_type": "lead",
      "id": "lead_ViJkLOWx4ZOa9q3eIMuxbBtT1EuNrQhw6DQ0XDm6lxs",
      "display_name": "Close",
      "status_label": "Qualified"
    }
  ]
}
```

**SDK Code**

```python Leads in a status, newest first
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = {
    "_fields": { "lead": ["display_name", "id", "status_label"] },
    "_limit": 2,
    "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "lead"
            },
            {
                "type": "field_condition",
                "condition": {
                    "type": "reference",
                    "object_ids": ["stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk"],
                    "reference_type": "status.lead"
                },
                "field": {
                    "type": "regular_field",
                    "field_name": "status_id",
                    "object_type": "lead"
                }
            }
        ]
    },
    "sort": [
        {
            "direction": "desc",
            "field": {
                "type": "regular_field",
                "field_name": "date_created",
                "object_type": "lead"
            }
        }
    ]
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Leads in a status, newest first
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"_fields":{"lead":["display_name","id","status_label"]},"_limit":2,"query":{"type":"and","queries":[{"type":"object_type","object_type":"lead"},{"type":"field_condition","condition":{"type":"reference","object_ids":["stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk"],"reference_type":"status.lead"},"field":{"type":"regular_field","field_name":"status_id","object_type":"lead"}}]},"sort":[{"direction":"desc","field":{"type":"regular_field","field_name":"date_created","object_type":"lead"}}]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Leads in a status, newest first
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"_fields\": {\n    \"lead\": [\n      \"display_name\",\n      \"id\",\n      \"status_label\"\n    ]\n  },\n  \"_limit\": 2,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"reference\",\n          \"object_ids\": [\n            \"stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk\"\n          ],\n          \"reference_type\": \"status.lead\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"status_id\",\n          \"object_type\": \"lead\"\n        }\n      }\n    ]\n  },\n  \"sort\": [\n    {\n      \"direction\": \"desc\",\n      \"field\": {\n        \"type\": \"regular_field\",\n        \"field_name\": \"date_created\",\n        \"object_type\": \"lead\"\n      }\n    }\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Leads in a status, newest first
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"_fields\": {\n    \"lead\": [\n      \"display_name\",\n      \"id\",\n      \"status_label\"\n    ]\n  },\n  \"_limit\": 2,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"reference\",\n          \"object_ids\": [\n            \"stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk\"\n          ],\n          \"reference_type\": \"status.lead\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"status_id\",\n          \"object_type\": \"lead\"\n        }\n      }\n    ]\n  },\n  \"sort\": [\n    {\n      \"direction\": \"desc\",\n      \"field\": {\n        \"type\": \"regular_field\",\n        \"field_name\": \"date_created\",\n        \"object_type\": \"lead\"\n      }\n    }\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java Leads in a status, newest first
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"_fields\": {\n    \"lead\": [\n      \"display_name\",\n      \"id\",\n      \"status_label\"\n    ]\n  },\n  \"_limit\": 2,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"reference\",\n          \"object_ids\": [\n            \"stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk\"\n          ],\n          \"reference_type\": \"status.lead\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"status_id\",\n          \"object_type\": \"lead\"\n        }\n      }\n    ]\n  },\n  \"sort\": [\n    {\n      \"direction\": \"desc\",\n      \"field\": {\n        \"type\": \"regular_field\",\n        \"field_name\": \"date_created\",\n        \"object_type\": \"lead\"\n      }\n    }\n  ]\n}")
  .asString();
```

```php Leads in a status, newest first
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "_fields": {
    "lead": [
      "display_name",
      "id",
      "status_label"
    ]
  },
  "_limit": 2,
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "reference",
          "object_ids": [
            "stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk"
          ],
          "reference_type": "status.lead"
        },
        "field": {
          "type": "regular_field",
          "field_name": "status_id",
          "object_type": "lead"
        }
      }
    ]
  },
  "sort": [
    {
      "direction": "desc",
      "field": {
        "type": "regular_field",
        "field_name": "date_created",
        "object_type": "lead"
      }
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Leads in a status, newest first
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"_fields\": {\n    \"lead\": [\n      \"display_name\",\n      \"id\",\n      \"status_label\"\n    ]\n  },\n  \"_limit\": 2,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"reference\",\n          \"object_ids\": [\n            \"stat_1ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk\"\n          ],\n          \"reference_type\": \"status.lead\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"status_id\",\n          \"object_type\": \"lead\"\n        }\n      }\n    ]\n  },\n  \"sort\": [\n    {\n      \"direction\": \"desc\",\n      \"field\": {\n        \"type\": \"regular_field\",\n        \"field_name\": \"date_created\",\n        \"object_type\": \"lead\"\n      }\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### My Leads created in the last 30 days, with a count

**Request**

```json
{
  "_fields": {
    "lead": [
      "date_created",
      "display_name",
      "id"
    ]
  },
  "include_counts": true,
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "current_user"
        },
        "field": {
          "type": "regular_field",
          "field_name": "created_by",
          "object_type": "lead"
        }
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "moment_range",
          "on_or_after": {
            "type": "offset",
            "direction": "past",
            "offset": {
              "days": 30
            }
          }
        },
        "field": {
          "type": "regular_field",
          "field_name": "date_created",
          "object_type": "lead"
        }
      }
    ]
  }
}
```

**Response**

```json
{
  "cursor": null,
  "data": [
    {
      "__object_type": "lead",
      "id": "lead_Wj0mVbjRrAhVeqOTnMHXdpcUBHAOPtmFbzoxK0U2Mn0",
      "date_created": "2024-05-02T14:12:31.217000+00:00",
      "display_name": "Bluth Company"
    }
  ],
  "count": {
    "limited": 1,
    "total": 1
  }
}
```

**SDK Code**

```python My Leads created in the last 30 days, with a count
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = {
    "_fields": { "lead": ["date_created", "display_name", "id"] },
    "include_counts": True,
    "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "lead"
            },
            {
                "type": "field_condition",
                "condition": { "type": "current_user" },
                "field": {
                    "type": "regular_field",
                    "field_name": "created_by",
                    "object_type": "lead"
                }
            },
            {
                "type": "field_condition",
                "condition": {
                    "type": "moment_range",
                    "on_or_after": {
                        "type": "offset",
                        "direction": "past",
                        "offset": { "days": 30 }
                    }
                },
                "field": {
                    "type": "regular_field",
                    "field_name": "date_created",
                    "object_type": "lead"
                }
            }
        ]
    }
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript My Leads created in the last 30 days, with a count
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"_fields":{"lead":["date_created","display_name","id"]},"include_counts":true,"query":{"type":"and","queries":[{"type":"object_type","object_type":"lead"},{"type":"field_condition","condition":{"type":"current_user"},"field":{"type":"regular_field","field_name":"created_by","object_type":"lead"}},{"type":"field_condition","condition":{"type":"moment_range","on_or_after":{"type":"offset","direction":"past","offset":{"days":30}}},"field":{"type":"regular_field","field_name":"date_created","object_type":"lead"}}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go My Leads created in the last 30 days, with a count
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"_fields\": {\n    \"lead\": [\n      \"date_created\",\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"include_counts\": true,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"current_user\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"created_by\",\n          \"object_type\": \"lead\"\n        }\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"moment_range\",\n          \"on_or_after\": {\n            \"type\": \"offset\",\n            \"direction\": \"past\",\n            \"offset\": {\n              \"days\": 30\n            }\n          }\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"date_created\",\n          \"object_type\": \"lead\"\n        }\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby My Leads created in the last 30 days, with a count
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"_fields\": {\n    \"lead\": [\n      \"date_created\",\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"include_counts\": true,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"current_user\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"created_by\",\n          \"object_type\": \"lead\"\n        }\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"moment_range\",\n          \"on_or_after\": {\n            \"type\": \"offset\",\n            \"direction\": \"past\",\n            \"offset\": {\n              \"days\": 30\n            }\n          }\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"date_created\",\n          \"object_type\": \"lead\"\n        }\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java My Leads created in the last 30 days, with a count
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"_fields\": {\n    \"lead\": [\n      \"date_created\",\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"include_counts\": true,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"current_user\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"created_by\",\n          \"object_type\": \"lead\"\n        }\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"moment_range\",\n          \"on_or_after\": {\n            \"type\": \"offset\",\n            \"direction\": \"past\",\n            \"offset\": {\n              \"days\": 30\n            }\n          }\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"date_created\",\n          \"object_type\": \"lead\"\n        }\n      }\n    ]\n  }\n}")
  .asString();
```

```php My Leads created in the last 30 days, with a count
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "_fields": {
    "lead": [
      "date_created",
      "display_name",
      "id"
    ]
  },
  "include_counts": true,
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "current_user"
        },
        "field": {
          "type": "regular_field",
          "field_name": "created_by",
          "object_type": "lead"
        }
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "moment_range",
          "on_or_after": {
            "type": "offset",
            "direction": "past",
            "offset": {
              "days": 30
            }
          }
        },
        "field": {
          "type": "regular_field",
          "field_name": "date_created",
          "object_type": "lead"
        }
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp My Leads created in the last 30 days, with a count
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"_fields\": {\n    \"lead\": [\n      \"date_created\",\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"include_counts\": true,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"current_user\"\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"created_by\",\n          \"object_type\": \"lead\"\n        }\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"moment_range\",\n          \"on_or_after\": {\n            \"type\": \"offset\",\n            \"direction\": \"past\",\n            \"offset\": {\n              \"days\": 30\n            }\n          }\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"date_created\",\n          \"object_type\": \"lead\"\n        }\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Leads by a choice custom field

**Request**

```json
{
  "_fields": {
    "lead": [
      "custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z",
      "display_name",
      "id"
    ]
  },
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "term",
          "values": [
            "Fintech",
            "Software as a service"
          ]
        },
        "field": {
          "type": "custom_field",
          "custom_field_id": "cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z"
        }
      }
    ]
  }
}
```

**Response**

```json
{
  "cursor": null,
  "data": [
    {
      "__object_type": "lead",
      "id": "lead_ViJkLOWx4ZOa9q3eIMuxbBtT1EuNrQhw6DQ0XDm6lxs",
      "custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z": "Software as a service",
      "display_name": "Close"
    }
  ]
}
```

**SDK Code**

```python Leads by a choice custom field
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = {
    "_fields": { "lead": ["custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z", "display_name", "id"] },
    "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "lead"
            },
            {
                "type": "field_condition",
                "condition": {
                    "type": "term",
                    "values": ["Fintech", "Software as a service"]
                },
                "field": {
                    "type": "custom_field",
                    "custom_field_id": "cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z"
                }
            }
        ]
    }
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Leads by a choice custom field
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"_fields":{"lead":["custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z","display_name","id"]},"query":{"type":"and","queries":[{"type":"object_type","object_type":"lead"},{"type":"field_condition","condition":{"type":"term","values":["Fintech","Software as a service"]},"field":{"type":"custom_field","custom_field_id":"cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z"}}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Leads by a choice custom field
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"_fields\": {\n    \"lead\": [\n      \"custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z\",\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"term\",\n          \"values\": [\n            \"Fintech\",\n            \"Software as a service\"\n          ]\n        },\n        \"field\": {\n          \"type\": \"custom_field\",\n          \"custom_field_id\": \"cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z\"\n        }\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Leads by a choice custom field
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"_fields\": {\n    \"lead\": [\n      \"custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z\",\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"term\",\n          \"values\": [\n            \"Fintech\",\n            \"Software as a service\"\n          ]\n        },\n        \"field\": {\n          \"type\": \"custom_field\",\n          \"custom_field_id\": \"cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z\"\n        }\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Leads by a choice custom field
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"_fields\": {\n    \"lead\": [\n      \"custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z\",\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"term\",\n          \"values\": [\n            \"Fintech\",\n            \"Software as a service\"\n          ]\n        },\n        \"field\": {\n          \"type\": \"custom_field\",\n          \"custom_field_id\": \"cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z\"\n        }\n      }\n    ]\n  }\n}")
  .asString();
```

```php Leads by a choice custom field
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "_fields": {
    "lead": [
      "custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z",
      "display_name",
      "id"
    ]
  },
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "term",
          "values": [
            "Fintech",
            "Software as a service"
          ]
        },
        "field": {
          "type": "custom_field",
          "custom_field_id": "cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z"
        }
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Leads by a choice custom field
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"_fields\": {\n    \"lead\": [\n      \"custom.cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z\",\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"term\",\n          \"values\": [\n            \"Fintech\",\n            \"Software as a service\"\n          ]\n        },\n        \"field\": {\n          \"type\": \"custom_field\",\n          \"custom_field_id\": \"cf_B57sofuEB7OBneH86SJctTr7hfiAiQcgkGRbAQfha0Z\"\n        }\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Leads with a CEO Contact

**Request**

```json
{
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "has_related",
        "related_object_type": "contact",
        "this_object_type": "lead",
        "related_query": {
          "type": "field_condition",
          "condition": {
            "type": "text",
            "mode": "full_words",
            "value": "CEO"
          },
          "field": {
            "type": "regular_field",
            "field_name": "title",
            "object_type": "contact"
          }
        }
      }
    ]
  }
}
```

**Response**

```json
{
  "cursor": null,
  "data": [
    {
      "__object_type": "lead",
      "id": "lead_Wj0mVbjRrAhVeqOTnMHXdpcUBHAOPtmFbzoxK0U2Mn0"
    }
  ]
}
```

**SDK Code**

```python Leads with a CEO Contact
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = { "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "lead"
            },
            {
                "type": "has_related",
                "related_object_type": "contact",
                "this_object_type": "lead",
                "related_query": {
                    "type": "field_condition",
                    "condition": {
                        "type": "text",
                        "mode": "full_words",
                        "value": "CEO"
                    },
                    "field": {
                        "type": "regular_field",
                        "field_name": "title",
                        "object_type": "contact"
                    }
                }
            }
        ]
    } }
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Leads with a CEO Contact
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"query":{"type":"and","queries":[{"type":"object_type","object_type":"lead"},{"type":"has_related","related_object_type":"contact","this_object_type":"lead","related_query":{"type":"field_condition","condition":{"type":"text","mode":"full_words","value":"CEO"},"field":{"type":"regular_field","field_name":"title","object_type":"contact"}}}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Leads with a CEO Contact
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"has_related\",\n        \"related_object_type\": \"contact\",\n        \"this_object_type\": \"lead\",\n        \"related_query\": {\n          \"type\": \"field_condition\",\n          \"condition\": {\n            \"type\": \"text\",\n            \"mode\": \"full_words\",\n            \"value\": \"CEO\"\n          },\n          \"field\": {\n            \"type\": \"regular_field\",\n            \"field_name\": \"title\",\n            \"object_type\": \"contact\"\n          }\n        }\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Leads with a CEO Contact
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"has_related\",\n        \"related_object_type\": \"contact\",\n        \"this_object_type\": \"lead\",\n        \"related_query\": {\n          \"type\": \"field_condition\",\n          \"condition\": {\n            \"type\": \"text\",\n            \"mode\": \"full_words\",\n            \"value\": \"CEO\"\n          },\n          \"field\": {\n            \"type\": \"regular_field\",\n            \"field_name\": \"title\",\n            \"object_type\": \"contact\"\n          }\n        }\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Leads with a CEO Contact
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"has_related\",\n        \"related_object_type\": \"contact\",\n        \"this_object_type\": \"lead\",\n        \"related_query\": {\n          \"type\": \"field_condition\",\n          \"condition\": {\n            \"type\": \"text\",\n            \"mode\": \"full_words\",\n            \"value\": \"CEO\"\n          },\n          \"field\": {\n            \"type\": \"regular_field\",\n            \"field_name\": \"title\",\n            \"object_type\": \"contact\"\n          }\n        }\n      }\n    ]\n  }\n}")
  .asString();
```

```php Leads with a CEO Contact
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "has_related",
        "related_object_type": "contact",
        "this_object_type": "lead",
        "related_query": {
          "type": "field_condition",
          "condition": {
            "type": "text",
            "mode": "full_words",
            "value": "CEO"
          },
          "field": {
            "type": "regular_field",
            "field_name": "title",
            "object_type": "contact"
          }
        }
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Leads with a CEO Contact
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"has_related\",\n        \"related_object_type\": \"contact\",\n        \"this_object_type\": \"lead\",\n        \"related_query\": {\n          \"type\": \"field_condition\",\n          \"condition\": {\n            \"type\": \"text\",\n            \"mode\": \"full_words\",\n            \"value\": \"CEO\"\n          },\n          \"field\": {\n            \"type\": \"regular_field\",\n            \"field_name\": \"title\",\n            \"object_type\": \"contact\"\n          }\n        }\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Leads not contacted in the last 2 weeks

**Request**

```json
{
  "_fields": {
    "lead": [
      "display_name",
      "id"
    ]
  },
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "moment_range",
          "on_or_after": {
            "type": "offset",
            "direction": "past",
            "offset": {
              "days": 14
            }
          }
        },
        "field": {
          "type": "regular_field",
          "field_name": "last_communication_date",
          "object_type": "lead"
        },
        "negate": true
      }
    ]
  }
}
```

**Response**

```json
{
  "cursor": null,
  "data": [
    {
      "__object_type": "lead",
      "id": "lead_ViJkLOWx4ZOa9q3eIMuxbBtT1EuNrQhw6DQ0XDm6lxs",
      "display_name": "Close"
    }
  ]
}
```

**SDK Code**

```python Leads not contacted in the last 2 weeks
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = {
    "_fields": { "lead": ["display_name", "id"] },
    "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "lead"
            },
            {
                "type": "field_condition",
                "condition": {
                    "type": "moment_range",
                    "on_or_after": {
                        "type": "offset",
                        "direction": "past",
                        "offset": { "days": 14 }
                    }
                },
                "field": {
                    "type": "regular_field",
                    "field_name": "last_communication_date",
                    "object_type": "lead"
                },
                "negate": True
            }
        ]
    }
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Leads not contacted in the last 2 weeks
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"_fields":{"lead":["display_name","id"]},"query":{"type":"and","queries":[{"type":"object_type","object_type":"lead"},{"type":"field_condition","condition":{"type":"moment_range","on_or_after":{"type":"offset","direction":"past","offset":{"days":14}}},"field":{"type":"regular_field","field_name":"last_communication_date","object_type":"lead"},"negate":true}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Leads not contacted in the last 2 weeks
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"_fields\": {\n    \"lead\": [\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"moment_range\",\n          \"on_or_after\": {\n            \"type\": \"offset\",\n            \"direction\": \"past\",\n            \"offset\": {\n              \"days\": 14\n            }\n          }\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"last_communication_date\",\n          \"object_type\": \"lead\"\n        },\n        \"negate\": true\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Leads not contacted in the last 2 weeks
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"_fields\": {\n    \"lead\": [\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"moment_range\",\n          \"on_or_after\": {\n            \"type\": \"offset\",\n            \"direction\": \"past\",\n            \"offset\": {\n              \"days\": 14\n            }\n          }\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"last_communication_date\",\n          \"object_type\": \"lead\"\n        },\n        \"negate\": true\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Leads not contacted in the last 2 weeks
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"_fields\": {\n    \"lead\": [\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"moment_range\",\n          \"on_or_after\": {\n            \"type\": \"offset\",\n            \"direction\": \"past\",\n            \"offset\": {\n              \"days\": 14\n            }\n          }\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"last_communication_date\",\n          \"object_type\": \"lead\"\n        },\n        \"negate\": true\n      }\n    ]\n  }\n}")
  .asString();
```

```php Leads not contacted in the last 2 weeks
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "_fields": {
    "lead": [
      "display_name",
      "id"
    ]
  },
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "moment_range",
          "on_or_after": {
            "type": "offset",
            "direction": "past",
            "offset": {
              "days": 14
            }
          }
        },
        "field": {
          "type": "regular_field",
          "field_name": "last_communication_date",
          "object_type": "lead"
        },
        "negate": true
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Leads not contacted in the last 2 weeks
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"_fields\": {\n    \"lead\": [\n      \"display_name\",\n      \"id\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"moment_range\",\n          \"on_or_after\": {\n            \"type\": \"offset\",\n            \"direction\": \"past\",\n            \"offset\": {\n              \"days\": 14\n            }\n          }\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"last_communication_date\",\n          \"object_type\": \"lead\"\n        },\n        \"negate\": true\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Leads with an outbound call last week

**Request**

```json
{
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "has_related",
        "related_object_type": "activity.call",
        "this_object_type": "lead",
        "related_query": {
          "type": "and",
          "queries": [
            {
              "type": "field_condition",
              "condition": {
                "type": "term",
                "values": [
                  "outbound"
                ]
              },
              "field": {
                "type": "regular_field",
                "field_name": "direction",
                "object_type": "activity.call"
              }
            },
            {
              "type": "field_condition",
              "condition": {
                "type": "predefined_relative_date_range",
                "value": "last-week"
              },
              "field": {
                "type": "regular_field",
                "field_name": "date_created",
                "object_type": "activity.call"
              }
            }
          ]
        }
      }
    ]
  }
}
```

**Response**

```json
{
  "cursor": null,
  "data": [
    {
      "__object_type": "lead",
      "id": "lead_Wj0mVbjRrAhVeqOTnMHXdpcUBHAOPtmFbzoxK0U2Mn0"
    }
  ]
}
```

**SDK Code**

```python Leads with an outbound call last week
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = { "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "lead"
            },
            {
                "type": "has_related",
                "related_object_type": "activity.call",
                "this_object_type": "lead",
                "related_query": {
                    "type": "and",
                    "queries": [
                        {
                            "type": "field_condition",
                            "condition": {
                                "type": "term",
                                "values": ["outbound"]
                            },
                            "field": {
                                "type": "regular_field",
                                "field_name": "direction",
                                "object_type": "activity.call"
                            }
                        },
                        {
                            "type": "field_condition",
                            "condition": {
                                "type": "predefined_relative_date_range",
                                "value": "last-week"
                            },
                            "field": {
                                "type": "regular_field",
                                "field_name": "date_created",
                                "object_type": "activity.call"
                            }
                        }
                    ]
                }
            }
        ]
    } }
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Leads with an outbound call last week
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"query":{"type":"and","queries":[{"type":"object_type","object_type":"lead"},{"type":"has_related","related_object_type":"activity.call","this_object_type":"lead","related_query":{"type":"and","queries":[{"type":"field_condition","condition":{"type":"term","values":["outbound"]},"field":{"type":"regular_field","field_name":"direction","object_type":"activity.call"}},{"type":"field_condition","condition":{"type":"predefined_relative_date_range","value":"last-week"},"field":{"type":"regular_field","field_name":"date_created","object_type":"activity.call"}}]}}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Leads with an outbound call last week
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"has_related\",\n        \"related_object_type\": \"activity.call\",\n        \"this_object_type\": \"lead\",\n        \"related_query\": {\n          \"type\": \"and\",\n          \"queries\": [\n            {\n              \"type\": \"field_condition\",\n              \"condition\": {\n                \"type\": \"term\",\n                \"values\": [\n                  \"outbound\"\n                ]\n              },\n              \"field\": {\n                \"type\": \"regular_field\",\n                \"field_name\": \"direction\",\n                \"object_type\": \"activity.call\"\n              }\n            },\n            {\n              \"type\": \"field_condition\",\n              \"condition\": {\n                \"type\": \"predefined_relative_date_range\",\n                \"value\": \"last-week\"\n              },\n              \"field\": {\n                \"type\": \"regular_field\",\n                \"field_name\": \"date_created\",\n                \"object_type\": \"activity.call\"\n              }\n            }\n          ]\n        }\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Leads with an outbound call last week
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"has_related\",\n        \"related_object_type\": \"activity.call\",\n        \"this_object_type\": \"lead\",\n        \"related_query\": {\n          \"type\": \"and\",\n          \"queries\": [\n            {\n              \"type\": \"field_condition\",\n              \"condition\": {\n                \"type\": \"term\",\n                \"values\": [\n                  \"outbound\"\n                ]\n              },\n              \"field\": {\n                \"type\": \"regular_field\",\n                \"field_name\": \"direction\",\n                \"object_type\": \"activity.call\"\n              }\n            },\n            {\n              \"type\": \"field_condition\",\n              \"condition\": {\n                \"type\": \"predefined_relative_date_range\",\n                \"value\": \"last-week\"\n              },\n              \"field\": {\n                \"type\": \"regular_field\",\n                \"field_name\": \"date_created\",\n                \"object_type\": \"activity.call\"\n              }\n            }\n          ]\n        }\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Leads with an outbound call last week
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"has_related\",\n        \"related_object_type\": \"activity.call\",\n        \"this_object_type\": \"lead\",\n        \"related_query\": {\n          \"type\": \"and\",\n          \"queries\": [\n            {\n              \"type\": \"field_condition\",\n              \"condition\": {\n                \"type\": \"term\",\n                \"values\": [\n                  \"outbound\"\n                ]\n              },\n              \"field\": {\n                \"type\": \"regular_field\",\n                \"field_name\": \"direction\",\n                \"object_type\": \"activity.call\"\n              }\n            },\n            {\n              \"type\": \"field_condition\",\n              \"condition\": {\n                \"type\": \"predefined_relative_date_range\",\n                \"value\": \"last-week\"\n              },\n              \"field\": {\n                \"type\": \"regular_field\",\n                \"field_name\": \"date_created\",\n                \"object_type\": \"activity.call\"\n              }\n            }\n          ]\n        }\n      }\n    ]\n  }\n}")
  .asString();
```

```php Leads with an outbound call last week
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      },
      {
        "type": "has_related",
        "related_object_type": "activity.call",
        "this_object_type": "lead",
        "related_query": {
          "type": "and",
          "queries": [
            {
              "type": "field_condition",
              "condition": {
                "type": "term",
                "values": [
                  "outbound"
                ]
              },
              "field": {
                "type": "regular_field",
                "field_name": "direction",
                "object_type": "activity.call"
              }
            },
            {
              "type": "field_condition",
              "condition": {
                "type": "predefined_relative_date_range",
                "value": "last-week"
              },
              "field": {
                "type": "regular_field",
                "field_name": "date_created",
                "object_type": "activity.call"
              }
            }
          ]
        }
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Leads with an outbound call last week
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      },\n      {\n        \"type\": \"has_related\",\n        \"related_object_type\": \"activity.call\",\n        \"this_object_type\": \"lead\",\n        \"related_query\": {\n          \"type\": \"and\",\n          \"queries\": [\n            {\n              \"type\": \"field_condition\",\n              \"condition\": {\n                \"type\": \"term\",\n                \"values\": [\n                  \"outbound\"\n                ]\n              },\n              \"field\": {\n                \"type\": \"regular_field\",\n                \"field_name\": \"direction\",\n                \"object_type\": \"activity.call\"\n              }\n            },\n            {\n              \"type\": \"field_condition\",\n              \"condition\": {\n                \"type\": \"predefined_relative_date_range\",\n                \"value\": \"last-week\"\n              },\n              \"field\": {\n                \"type\": \"regular_field\",\n                \"field_name\": \"date_created\",\n                \"object_type\": \"activity.call\"\n              }\n            }\n          ]\n        }\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Won Opportunities over $1,000

**Request**

```json
{
  "_fields": {
    "opportunity": [
      "id",
      "lead_name",
      "status_label",
      "value"
    ]
  },
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "opportunity"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "term",
          "values": [
            "won"
          ]
        },
        "field": {
          "type": "regular_field",
          "field_name": "status_type",
          "object_type": "opportunity"
        }
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "number_range",
          "gt": 100000
        },
        "field": {
          "type": "regular_field",
          "field_name": "value",
          "object_type": "opportunity"
        }
      }
    ]
  }
}
```

**Response**

```json
{
  "cursor": null,
  "data": [
    {
      "__object_type": "opportunity",
      "id": "oppo_8eB77gAdf8FMy6GsNHEy84f7uoeEWv55slvUjKQZpJt",
      "lead_name": "Bluth Company",
      "status_label": "Won",
      "value": 250000
    }
  ]
}
```

**SDK Code**

```python Won Opportunities over $1,000
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = {
    "_fields": { "opportunity": ["id", "lead_name", "status_label", "value"] },
    "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "opportunity"
            },
            {
                "type": "field_condition",
                "condition": {
                    "type": "term",
                    "values": ["won"]
                },
                "field": {
                    "type": "regular_field",
                    "field_name": "status_type",
                    "object_type": "opportunity"
                }
            },
            {
                "type": "field_condition",
                "condition": {
                    "type": "number_range",
                    "gt": 100000
                },
                "field": {
                    "type": "regular_field",
                    "field_name": "value",
                    "object_type": "opportunity"
                }
            }
        ]
    }
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Won Opportunities over $1,000
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"_fields":{"opportunity":["id","lead_name","status_label","value"]},"query":{"type":"and","queries":[{"type":"object_type","object_type":"opportunity"},{"type":"field_condition","condition":{"type":"term","values":["won"]},"field":{"type":"regular_field","field_name":"status_type","object_type":"opportunity"}},{"type":"field_condition","condition":{"type":"number_range","gt":100000},"field":{"type":"regular_field","field_name":"value","object_type":"opportunity"}}]}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Won Opportunities over $1,000
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"_fields\": {\n    \"opportunity\": [\n      \"id\",\n      \"lead_name\",\n      \"status_label\",\n      \"value\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"opportunity\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"term\",\n          \"values\": [\n            \"won\"\n          ]\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"status_type\",\n          \"object_type\": \"opportunity\"\n        }\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"number_range\",\n          \"gt\": 100000\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"value\",\n          \"object_type\": \"opportunity\"\n        }\n      }\n    ]\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Won Opportunities over $1,000
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"_fields\": {\n    \"opportunity\": [\n      \"id\",\n      \"lead_name\",\n      \"status_label\",\n      \"value\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"opportunity\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"term\",\n          \"values\": [\n            \"won\"\n          ]\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"status_type\",\n          \"object_type\": \"opportunity\"\n        }\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"number_range\",\n          \"gt\": 100000\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"value\",\n          \"object_type\": \"opportunity\"\n        }\n      }\n    ]\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java Won Opportunities over $1,000
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"_fields\": {\n    \"opportunity\": [\n      \"id\",\n      \"lead_name\",\n      \"status_label\",\n      \"value\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"opportunity\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"term\",\n          \"values\": [\n            \"won\"\n          ]\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"status_type\",\n          \"object_type\": \"opportunity\"\n        }\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"number_range\",\n          \"gt\": 100000\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"value\",\n          \"object_type\": \"opportunity\"\n        }\n      }\n    ]\n  }\n}")
  .asString();
```

```php Won Opportunities over $1,000
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "_fields": {
    "opportunity": [
      "id",
      "lead_name",
      "status_label",
      "value"
    ]
  },
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "opportunity"
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "term",
          "values": [
            "won"
          ]
        },
        "field": {
          "type": "regular_field",
          "field_name": "status_type",
          "object_type": "opportunity"
        }
      },
      {
        "type": "field_condition",
        "condition": {
          "type": "number_range",
          "gt": 100000
        },
        "field": {
          "type": "regular_field",
          "field_name": "value",
          "object_type": "opportunity"
        }
      }
    ]
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Won Opportunities over $1,000
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"_fields\": {\n    \"opportunity\": [\n      \"id\",\n      \"lead_name\",\n      \"status_label\",\n      \"value\"\n    ]\n  },\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"opportunity\"\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"term\",\n          \"values\": [\n            \"won\"\n          ]\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"status_type\",\n          \"object_type\": \"opportunity\"\n        }\n      },\n      {\n        \"type\": \"field_condition\",\n        \"condition\": {\n          \"type\": \"number_range\",\n          \"gt\": 100000\n        },\n        \"field\": {\n          \"type\": \"regular_field\",\n          \"field_name\": \"value\",\n          \"object_type\": \"opportunity\"\n        }\n      }\n    ]\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

### Count matching Leads

**Request**

```json
{
  "include_counts": true,
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      }
    ]
  },
  "results_limit": 0
}
```

**Response**

```json
{
  "cursor": null,
  "data": [],
  "count": {
    "limited": 0,
    "total": 1532
  }
}
```

**SDK Code**

```python Count matching Leads
import requests

url = "https://api.close.com/api/v1/data/search/"

payload = {
    "include_counts": True,
    "query": {
        "type": "and",
        "queries": [
            {
                "type": "object_type",
                "object_type": "lead"
            }
        ]
    },
    "results_limit": 0
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript Count matching Leads
const url = 'https://api.close.com/api/v1/data/search/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"include_counts":true,"query":{"type":"and","queries":[{"type":"object_type","object_type":"lead"}]},"results_limit":0}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Count matching Leads
package main

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

func main() {

	url := "https://api.close.com/api/v1/data/search/"

	payload := strings.NewReader("{\n  \"include_counts\": true,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      }\n    ]\n  },\n  \"results_limit\": 0\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Count matching Leads
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/data/search/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"include_counts\": true,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      }\n    ]\n  },\n  \"results_limit\": 0\n}"

response = http.request(request)
puts response.read_body
```

```java Count matching Leads
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/data/search/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"include_counts\": true,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      }\n    ]\n  },\n  \"results_limit\": 0\n}")
  .asString();
```

```php Count matching Leads
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/data/search/', [
  'body' => '{
  "include_counts": true,
  "query": {
    "type": "and",
    "queries": [
      {
        "type": "object_type",
        "object_type": "lead"
      }
    ]
  },
  "results_limit": 0
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp Count matching Leads
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/data/search/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"include_counts\": true,\n  \"query\": {\n    \"type\": \"and\",\n    \"queries\": [\n      {\n        \"type\": \"object_type\",\n        \"object_type\": \"lead\"\n      }\n    ]\n  },\n  \"results_limit\": 0\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```