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

# Attach a file to a lead

POST https://api.close.com/api/v1/lead/{id}/files/
Content-Type: application/json

Attach an already-uploaded file to a lead. First upload the file to S3 using the [Files API](https://developer.close.com/api/resources/files), then pass the resulting download `url` here along with its `filename` and `content_type`.

Reference: https://developer.close.com/api/resources/leads/files-create

## Authentication

- `Authorization` header (basic auth, required) — Use your API key as the username and leave the password empty.
- `Authorization` header (bearer token, required)

## Request

### Path parameters

- `id` (string, required)

### Body (application/json)

- `content_type` (string, required)
- `filename` (string, required)
- `url` (string, required)

## Response

### 201

Successful response

- `checksum` (string, required)
- `content_type` (string, required)
- `date_created` (datetime, required)
- `date_updated` (datetime, required)
- `download_url` (string, required)
- `id` (string, required)
- `is_pinned` (boolean, required)
- `last_activity_at` (datetime, required)
- `last_object_id` (string, required)
- `last_object_type` (string, required)
- `lead_id` (string, required)
- `name` (string, required)
- `organization_id` (string, required)
- `size` (integer, required)
- `thumbnail_url` (string, required, nullable)
- `updated_by` (string, required, nullable)

## Examples

**Request**

```json
{
  "content_type": "application/pdf",
  "filename": "contract.pdf",
  "url": "https://app.close.com/go/file/temporary/user_Ova4RGFG7pztSeJiiMFdN7O2MFl71nD0uGO3bIOo4Wk/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/"
}
```

**Response**

```json
{
  "checksum": "d41d8cd98f00b204e9800998ecf8427e",
  "content_type": "application/pdf",
  "date_created": "2024-03-07T16:07:00+00:00",
  "date_updated": "2024-03-07T16:07:00+00:00",
  "download_url": "https://app.close.com/go/file/persisted/orga_RbREgmiiwcr1w2b4cOnCMQaQPSIFxMqAD2Dh243uxcH/activity.email/acti_5rV2n1Ub/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/",
  "id": "file_2Lm4kZ8Qqwe0rTaPnB6yXcVd9sHgKfJoMuIlN3vBz1A",
  "is_pinned": false,
  "last_activity_at": "2024-03-07T16:07:00+00:00",
  "last_object_id": "acti_5rV2n1UbQ8mLkJhGfDsAwErTyUiOpZxCvBnM3aQ",
  "last_object_type": "activity.email",
  "lead_id": "lead_70jZ5hiVt5X31MZ3vJ0R0GJMqJEihkoF7TtSVFbN2ty",
  "name": "contract.pdf",
  "organization_id": "orga_RbREgmiiwcr1w2b4cOnCMQaQPSIFxMqAD2Dh243uxcH",
  "size": 20480,
  "thumbnail_url": null,
  "updated_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA"
}
```

**SDK Code**

```python leads_filesCreate_example
import requests

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

payload = {
    "content_type": "application/pdf",
    "filename": "contract.pdf",
    "url": "https://app.close.com/go/file/temporary/user_Ova4RGFG7pztSeJiiMFdN7O2MFl71nD0uGO3bIOo4Wk/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/"
}
headers = {
    "Content-Type": "application/json"
}

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

print(response.json())
```

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

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"content_type":"application/pdf","filename":"contract.pdf","url":"https://app.close.com/go/file/temporary/user_Ova4RGFG7pztSeJiiMFdN7O2MFl71nD0uGO3bIOo4Wk/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/"}'
};

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

```go leads_filesCreate_example
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"content_type\": \"application/pdf\",\n  \"filename\": \"contract.pdf\",\n  \"url\": \"https://app.close.com/go/file/temporary/user_Ova4RGFG7pztSeJiiMFdN7O2MFl71nD0uGO3bIOo4Wk/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/\"\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_filesCreate_example
require 'uri'
require 'net/http'

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

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  \"content_type\": \"application/pdf\",\n  \"filename\": \"contract.pdf\",\n  \"url\": \"https://app.close.com/go/file/temporary/user_Ova4RGFG7pztSeJiiMFdN7O2MFl71nD0uGO3bIOo4Wk/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/\"\n}"

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

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

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/lead/id/files/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"content_type\": \"application/pdf\",\n  \"filename\": \"contract.pdf\",\n  \"url\": \"https://app.close.com/go/file/temporary/user_Ova4RGFG7pztSeJiiMFdN7O2MFl71nD0uGO3bIOo4Wk/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/lead/id/files/', [
  'body' => '{
  "content_type": "application/pdf",
  "filename": "contract.pdf",
  "url": "https://app.close.com/go/file/temporary/user_Ova4RGFG7pztSeJiiMFdN7O2MFl71nD0uGO3bIOo4Wk/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

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

```csharp leads_filesCreate_example
using RestSharp;
using RestSharp.Authenticators;

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

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"content_type\": \"application/pdf\",\n  \"filename\": \"contract.pdf\",\n  \"url\": \"https://app.close.com/go/file/temporary/user_Ova4RGFG7pztSeJiiMFdN7O2MFl71nD0uGO3bIOo4Wk/1Zx0AlY1DwBXzKKrVwpAoj/contract.pdf/\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```