# Create Attachment

Create an attachment that links a resource, such as a file or folder, to any CRM record. The linked resource can be directly viewed from the CRM record using the CloudFiles widget post successful attachment.

> Kind: REST endpoint · Updated: Mar 6, 2026 · POST /v1/attachments

Create an attachment that links a resource, such as a file or folder, to any CRM record. The linked resource can be directly viewed from the CRM record using the CloudFiles widget post successful attachment.

### Query parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| library | string | optional | One of sharepoint, msteams, google, onedrive, box, dropbox, cloudfiles, s3, azure, hubspot, azurefiles, sftp |
| driveId | string | optional | Drive Id. Required when library is sharepoint or msteams. |

### Header parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| Authorization | string | optional | Replace the API_Key placeholder with your actual API key. |

## Request body

```json
{
  "resource": "{{resource-id}}",
  "resourceType": "folder",
  "source": "SALESFORCE",
  "objectType": "contact",
  "objectId": "003dL00001Xml6JQAR"
}
```

## Example request

**cURL**
```bash
curl --request POST \
     --url 'https://api.cloudfiles.io/v1/attachments?library=string&driveId=string' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'authorization: Bearer API_Key' \
     --data '"{\n  \"resource\": \"{{resource-id}}\",\n  \"resourceType\": \"folder\",\n  \"source\": \"SALESFORCE\",\n  \"objectType\": \"contact\",\n  \"objectId\": \"003dL00001Xml6JQAR\"\n}"'
```

**JavaScript**
```js
var myHeaders = new Headers();
myHeaders.append("accept", "application/json");
myHeaders.append("content-type", "application/json");
myHeaders.append("authorization", "Bearer API_Key");
myHeaders.append("", "string");

var raw = JSON.stringify("{\n  \"resource\": \"{{resource-id}}\",\n  \"resourceType\": \"folder\",\n  \"source\": \"SALESFORCE\",\n  \"objectType\": \"contact\",\n  \"objectId\": \"003dL00001Xml6JQAR\"\n}");

var requestOptions = {
   method: 'POST',
   headers: myHeaders,
   body: raw,
   redirect: 'follow'
};

fetch("https://api.cloudfiles.io/v1/attachments?library=string&driveId=string", requestOptions)
   .then(response => response.text())
   .then(result => console.log(result))
   .catch(error => console.log('error', error));
```

**Ruby**
```ruby
require "uri"
require "json"
require "net/http"

url = URI("https://api.cloudfiles.io/v1/attachments?library=string&driveId=string")

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

request = Net::HTTP::Post.new(url)
request["accept"] = "application/json"
request["content-type"] = "application/json"
request["authorization"] = "Bearer API_Key"
request[""] = "string"
request.body = JSON.dump("{\n  \"resource\": \"{{resource-id}}\",\n  \"resourceType\": \"folder\",\n  \"source\": \"SALESFORCE\",\n  \"objectType\": \"contact\",\n  \"objectId\": \"003dL00001Xml6JQAR\"\n}")

response = https.request(request)
puts response.read_body

```

**Python**
```py
import requests
import json

url = "https://api.cloudfiles.io/v1/attachments?library=string&driveId=string"

payload = json.dumps("{\n  \"resource\": \"{{resource-id}}\",\n  \"resourceType\": \"folder\",\n  \"source\": \"SALESFORCE\",\n  \"objectType\": \"contact\",\n  \"objectId\": \"003dL00001Xml6JQAR\"\n}")
headers = {
   'accept': 'application/json',
   'content-type': 'application/json',
   'authorization': 'Bearer API_Key',
   '': 'string'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

## Response body

```json
{
  "id": "att_123",
  "type": "external",
  "objectId": "deal_456",
  "objectType": "hubspot_deal",
  "createdAt": "2026-07-05T10:00:00Z",
  "createdBy": "usr_1"
}
```
