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

# Export leads based on a search query

POST https://api.close.com/api/v1/export/lead/
Content-Type: application/json

You will receive a link to the generated file via email once the export is done.

The exported file is GZIP compressed to make your download and our upload faster. The `content-encoding` HTTP header will be set to `gzip` and the `content-type` HTTP header will be set to `text/csv` for CSV exports or `application/json` for JSON exports.

Parameters:
  - `s_query/results_limit/sort` (optional) - The [Advanced Filtering API](https://developer.close.com/api/resources/advanced-filtering) parameters used to narrow the exported results down. By default, all leads are exported.
  - `format` - Format of the exported file. The choices are: `csv`, `json`. JSON is recommended for raw backups or data migrations.
  - `type` - Type of the export.
    - `leads` - For CSV exports, it results in one row per lead. For JSON exports, this is the recommended type and is a superset of the other two types.
    - `contacts` - For CSV exports, it results in one row per contact.
    - `lead_opps` - For CSV exports, it results in one row per opportunity.
  - `date_format` (optional) - Controls the format of date objects. Note: this only works with the `csv` format.
    - `original` (default) - A date format that includes microseconds and timezone information.
        - Date: `[YYYY]-[MM]-[DD]`
        - Date w/ time: `[YYYY]-[MM]-[DD] [hh]:[mm]:[ss.sssss]±[hh]:[mm]`
    - `iso8601` (recommended) - An [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) compatible date representation that does not include microseconds.
        - Date: `[YYYY]-[MM]-[DD]`
        - Date w/ time: `[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]±[hh]:[mm]`
    - `excel` - An Excel compatible date format. Dates are always in UTC, do not include timezone information or microseconds, and use a 12 hour clock with an AM or PM designation.
        - Date: `[YYYY]-[MM]-[DD]`
        - Date w/ time: `[YYYY]-[MM]-[DD] [hh]:[mm]:[ss] [AM|PM]`
  - `fields` (optional) - By default we return all the data fields in each export type. If you only need specific fields exported, you can explicitly list them in `fields` to get smaller exports.
  - `include_activities` (optional) - Activities aren't included in any exports by default. If you want all your Activities exported as well, pass `"include_activities": true`. Note: this only works for `leads` type with `json` format.
  - `include_smart_fields` (optional) - Smart Fields aren't included in any exports by default. If you want all of them exported as well, pass `"include_smart_fields": true`. Note: this only works for `leads` type with `json` format or any type formatted as `csv`. Smart fields are calculated fields, like number of emails on a lead.
  - `send_done_email` - Set to `false` if you don't want to get a confirmation email after the bulk action is done.

Reference: https://developer.close.com/api/resources/exports/create-lead

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: Close API
  version: 1.0.0
paths:
  /export/lead/:
    post:
      operationId: create-lead
      summary: Export leads based on a search query
      description: >-
        You will receive a link to the generated file via email once the export
        is done.


        The exported file is GZIP compressed to make your download and our
        upload faster. The `content-encoding` HTTP header will be set to `gzip`
        and the `content-type` HTTP header will be set to `text/csv` for CSV
        exports or `application/json` for JSON exports.


        Parameters:
          - `s_query/results_limit/sort` (optional) - The [Advanced Filtering API](https://developer.close.com/api/resources/advanced-filtering) parameters used to narrow the exported results down. By default, all leads are exported.
          - `format` - Format of the exported file. The choices are: `csv`, `json`. JSON is recommended for raw backups or data migrations.
          - `type` - Type of the export.
            - `leads` - For CSV exports, it results in one row per lead. For JSON exports, this is the recommended type and is a superset of the other two types.
            - `contacts` - For CSV exports, it results in one row per contact.
            - `lead_opps` - For CSV exports, it results in one row per opportunity.
          - `date_format` (optional) - Controls the format of date objects. Note: this only works with the `csv` format.
            - `original` (default) - A date format that includes microseconds and timezone information.
                - Date: `[YYYY]-[MM]-[DD]`
                - Date w/ time: `[YYYY]-[MM]-[DD] [hh]:[mm]:[ss.sssss]±[hh]:[mm]`
            - `iso8601` (recommended) - An [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) compatible date representation that does not include microseconds.
                - Date: `[YYYY]-[MM]-[DD]`
                - Date w/ time: `[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]±[hh]:[mm]`
            - `excel` - An Excel compatible date format. Dates are always in UTC, do not include timezone information or microseconds, and use a 12 hour clock with an AM or PM designation.
                - Date: `[YYYY]-[MM]-[DD]`
                - Date w/ time: `[YYYY]-[MM]-[DD] [hh]:[mm]:[ss] [AM|PM]`
          - `fields` (optional) - By default we return all the data fields in each export type. If you only need specific fields exported, you can explicitly list them in `fields` to get smaller exports.
          - `include_activities` (optional) - Activities aren't included in any exports by default. If you want all your Activities exported as well, pass `"include_activities": true`. Note: this only works for `leads` type with `json` format.
          - `include_smart_fields` (optional) - Smart Fields aren't included in any exports by default. If you want all of them exported as well, pass `"include_smart_fields": true`. Note: this only works for `leads` type with `json` format or any type formatted as `csv`. Smart fields are calculated fields, like number of emails on a lead.
          - `send_done_email` - Set to `false` if you don't want to get a confirmation email after the bulk action is done.
      tags:
        - subpackage_exports
      parameters:
        - name: Authorization
          in: header
          description: Use your API key as the username and leave the password empty.
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/exports_createLead_Response_200'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                description: Any type
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                description: Any type
        '404':
          description: Not found
          content:
            application/json:
              schema:
                description: Any type
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateExportFlags'
servers:
  - url: https://api.close.com/api/v1
components:
  schemas:
    CreateExportFlags:
      type: object
      properties:
        include_activities:
          type: boolean
          default: false
        include_addresses:
          type: boolean
        include_custom_objects:
          type: boolean
          default: false
        include_smart_fields:
          type: boolean
          default: false
      title: CreateExportFlags
    exports_createLead_Response_200:
      type: object
      properties: {}
      description: Empty response body
      title: exports_createLead_Response_200
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: basic
      description: Use your API key as the username and leave the password empty.
    OAuth2:
      type: http
      scheme: bearer

```

## SDK Code Examples

```python exports_createLead_example
import requests

url = "https://api.close.com/api/v1/export/lead/"

payload = {
    "date_format": "iso8601",
    "format": "csv",
    "results_limit": None,
    "s_query": {
        "queries": [
            {
                "object_type": "lead",
                "type": "object_type"
            },
            {
                "condition": {
                    "mode": "full_words",
                    "type": "text",
                    "value": "ACME Inc."
                },
                "field": {
                    "field_name": "name",
                    "object_type": "lead",
                    "type": "regular_field"
                },
                "type": "field_condition"
            }
        ],
        "type": "and"
    },
    "send_done_email": False,
    "sort": [
        {
            "direction": "desc",
            "field": {
                "field_name": "date_created",
                "object_type": "lead",
                "type": "regular_field"
            }
        }
    ],
    "type": "leads"
}
headers = {
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript exports_createLead_example
const url = 'https://api.close.com/api/v1/export/lead/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"date_format":"iso8601","format":"csv","results_limit":null,"s_query":{"queries":[{"object_type":"lead","type":"object_type"},{"condition":{"mode":"full_words","type":"text","value":"ACME Inc."},"field":{"field_name":"name","object_type":"lead","type":"regular_field"},"type":"field_condition"}],"type":"and"},"send_done_email":false,"sort":[{"direction":"desc","field":{"field_name":"date_created","object_type":"lead","type":"regular_field"}}],"type":"leads"}'
};

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

```go exports_createLead_example
package main

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

func main() {

	url := "https://api.close.com/api/v1/export/lead/"

	payload := strings.NewReader("{\n  \"date_format\": \"iso8601\",\n  \"format\": \"csv\",\n  \"results_limit\": null,\n  \"s_query\": {\n    \"queries\": [\n      {\n        \"object_type\": \"lead\",\n        \"type\": \"object_type\"\n      },\n      {\n        \"condition\": {\n          \"mode\": \"full_words\",\n          \"type\": \"text\",\n          \"value\": \"ACME Inc.\"\n        },\n        \"field\": {\n          \"field_name\": \"name\",\n          \"object_type\": \"lead\",\n          \"type\": \"regular_field\"\n        },\n        \"type\": \"field_condition\"\n      }\n    ],\n    \"type\": \"and\"\n  },\n  \"send_done_email\": false,\n  \"sort\": [\n    {\n      \"direction\": \"desc\",\n      \"field\": {\n        \"field_name\": \"date_created\",\n        \"object_type\": \"lead\",\n        \"type\": \"regular_field\"\n      }\n    }\n  ],\n  \"type\": \"leads\"\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 exports_createLead_example
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/export/lead/")

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  \"date_format\": \"iso8601\",\n  \"format\": \"csv\",\n  \"results_limit\": null,\n  \"s_query\": {\n    \"queries\": [\n      {\n        \"object_type\": \"lead\",\n        \"type\": \"object_type\"\n      },\n      {\n        \"condition\": {\n          \"mode\": \"full_words\",\n          \"type\": \"text\",\n          \"value\": \"ACME Inc.\"\n        },\n        \"field\": {\n          \"field_name\": \"name\",\n          \"object_type\": \"lead\",\n          \"type\": \"regular_field\"\n        },\n        \"type\": \"field_condition\"\n      }\n    ],\n    \"type\": \"and\"\n  },\n  \"send_done_email\": false,\n  \"sort\": [\n    {\n      \"direction\": \"desc\",\n      \"field\": {\n        \"field_name\": \"date_created\",\n        \"object_type\": \"lead\",\n        \"type\": \"regular_field\"\n      }\n    }\n  ],\n  \"type\": \"leads\"\n}"

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

```java exports_createLead_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/export/lead/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"date_format\": \"iso8601\",\n  \"format\": \"csv\",\n  \"results_limit\": null,\n  \"s_query\": {\n    \"queries\": [\n      {\n        \"object_type\": \"lead\",\n        \"type\": \"object_type\"\n      },\n      {\n        \"condition\": {\n          \"mode\": \"full_words\",\n          \"type\": \"text\",\n          \"value\": \"ACME Inc.\"\n        },\n        \"field\": {\n          \"field_name\": \"name\",\n          \"object_type\": \"lead\",\n          \"type\": \"regular_field\"\n        },\n        \"type\": \"field_condition\"\n      }\n    ],\n    \"type\": \"and\"\n  },\n  \"send_done_email\": false,\n  \"sort\": [\n    {\n      \"direction\": \"desc\",\n      \"field\": {\n        \"field_name\": \"date_created\",\n        \"object_type\": \"lead\",\n        \"type\": \"regular_field\"\n      }\n    }\n  ],\n  \"type\": \"leads\"\n}")
  .asString();
```

```php exports_createLead_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/export/lead/', [
  'body' => '{
  "date_format": "iso8601",
  "format": "csv",
  "results_limit": null,
  "s_query": {
    "queries": [
      {
        "object_type": "lead",
        "type": "object_type"
      },
      {
        "condition": {
          "mode": "full_words",
          "type": "text",
          "value": "ACME Inc."
        },
        "field": {
          "field_name": "name",
          "object_type": "lead",
          "type": "regular_field"
        },
        "type": "field_condition"
      }
    ],
    "type": "and"
  },
  "send_done_email": false,
  "sort": [
    {
      "direction": "desc",
      "field": {
        "field_name": "date_created",
        "object_type": "lead",
        "type": "regular_field"
      }
    }
  ],
  "type": "leads"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

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

```csharp exports_createLead_example
using RestSharp;
using RestSharp.Authenticators;

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

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"date_format\": \"iso8601\",\n  \"format\": \"csv\",\n  \"results_limit\": null,\n  \"s_query\": {\n    \"queries\": [\n      {\n        \"object_type\": \"lead\",\n        \"type\": \"object_type\"\n      },\n      {\n        \"condition\": {\n          \"mode\": \"full_words\",\n          \"type\": \"text\",\n          \"value\": \"ACME Inc.\"\n        },\n        \"field\": {\n          \"field_name\": \"name\",\n          \"object_type\": \"lead\",\n          \"type\": \"regular_field\"\n        },\n        \"type\": \"field_condition\"\n      }\n    ],\n    \"type\": \"and\"\n  },\n  \"send_done_email\": false,\n  \"sort\": [\n    {\n      \"direction\": \"desc\",\n      \"field\": {\n        \"field_name\": \"date_created\",\n        \"object_type\": \"lead\",\n        \"type\": \"regular_field\"\n      }\n    }\n  ],\n  \"type\": \"leads\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```