# Create attachment

> **BETA**

#### Description
Creates or updates an attachment for future use as an attachment to a calendar event.

These are uploaded first via this API, and then available to be [attached to an event](/developers/api/attachments/attaching-to-event/index.md).

#### URL format
```
{data_center_url}/v1/attachments
```

#### Example Request
```http
POST /v1/attachments HTTP/1.1
Host: {data_center_url}
Authorization: Bearer {API_KEY}
Content-Type: application/json; charset=utf-8

{
  "attachment": {
    "file_name": "job_description.pdf",
    "content_type": "application/pdf",
    "base64_content": "TmV2ZXIgZ29ubmEgZ2l2ZSB5b3UgdXAK..."
  },
  "subscriptions": [
    {
      "type": "webhook",
      "uri": "https://example.com/customer_123/webhooks",
      "interactions": [
        { "type": "attachment_approved" },
        { "type": "attachment_rejected" },
      ]
    }
  ]
}
```

#### Example Response
```http
HTTP/1.1 200 Success

{
    "attachment": {
        "attachment_id": "att_5e4d5a6668ed0f4b213e90fe",
        "file_name": "my-file.pdf",
        "content_type": "application/pdf",
        "md5": "344aab9758bb0d018b93739e7893fb3a"
    }
}
```

#### Request parameters
##### data_center_url (required)
The URL for the data center you want to communicate with. Possible choices are:

- `api-au.cronofy.com` - Australia

- `api-ca.cronofy.com` - Canada

- `api-de.cronofy.com` - Germany

- `api-sg.cronofy.com` - Singapore

- `api-uk.cronofy.com` - United Kingdom

- `api.cronofy.com` - United States

Find out more about [Cronofy's data centers](/developers/data-centers/index.md).

##### `attachment` *(required)*

Object describing the Attachment.

##### `attachment.file_name` *(required)*

The file name to be used when attached to an event.

Please note that the file extension must be in the list expected for the content type. For example, `application/pdf` will require the `filename` to end in `.pdf`.

Also, to maximise compatibility, we restrict the characters usable in the file name. If you believe a name should be valid but isn't, please contact
[support@cronofy.com](mailto:support@cronofy.com).

##### `attachment.content_type` *(required)*

The MIME type for the attachment. This must match the file extension.

Note this is the `Content-Type` for the *attachment part* of the request. The `Content-Type` for the overall request must be `application/json`.

##### Supported content types
<table>
  <thead>
    <tr>
      <th>Type of file</th>
      <th>Content-Type</th>
      <th>Supported extensions</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Text File</td>
      <td>text/plain</td>
      <td>.txt, .asc, .c, .cc, .h, .hh, .cpp, .hpp, .dat, .hlp, .conf, .def, .doc, .in, .list, .log, .rst, .text, .textile</td>
    </tr>
    <tr>
      <td>Comma-Separated Values</td>
      <td>text/csv</td>
      <td>.csv</td>
    </tr>
    <tr>
      <td>Rich Text Format</td>
      <td>application/rtf</td>
      <td>.rtf</td>
    </tr>
    <tr>
      <td>Adobe Portable Document Format</td>
      <td>application/pdf</td>
      <td>.pdf, .ai</td>
    </tr>
    <tr>
      <td>Bitmap Image File</td>
      <td>image/bmp</td>
      <td>.bmp</td>
    </tr>
    <tr>
      <td>Graphics Interchange Format</td>
      <td>image/gif</td>
      <td>.gif</td>
    </tr>
    <tr>
      <td>JPEG Image</td>
      <td>image/jpeg</td>
      <td>.jpeg, .jpg, .jpe</td>
    </tr>
    <tr>
      <td>Portable Network Graphics (PNG)</td>
      <td>image/png</td>
      <td>.png</td>
    </tr>
    <tr>
      <td>Microsoft Word</td>
      <td>application/msword</td>
      <td>.doc, .dot, .wrd</td>
    </tr>
    <tr>
      <td>Microsoft Office - OOXML - Word Document</td>
      <td>application/vnd.openxmlformats-officedocument.wordprocessingml.document</td>
      <td>.docx</td>
    </tr>
    <tr>
      <td>Microsoft PowerPoint</td>
      <td>application/vnd.ms-powerpoint</td>
      <td>.ppt, .pps, .pot</td>
    </tr>
    <tr>
      <td>Microsoft Office - OOXML - Presentation</td>
      <td>application/vnd.openxmlformats-officedocument.presentationml.presentation</td>
      <td>.pptx</td>
    </tr>
    <tr>
      <td>Gzip archive</td>
      <td>application/gzip</td>
      <td>.gz</td>
    </tr>
    <tr>
      <td>Zip Archive</td>
      <td>application/zip</td>
      <td>.zip</td>
    </tr>
    <tr>
      <td>7-Zip</td>
      <td>application/x-7z-compressed</td>
      <td>.7z</td>
    </tr>
    <tr>
      <td>Microsoft Visio</td>
      <td>application/vnd.visio</td>
      <td>.vsd, .vst, .vsw, .vss</td>
    </tr>
    <tr>
      <td>Microsoft Excel</td>
      <td>application/vnd.ms-excel</td>
      <td>.xls, .xlt, .xla, .xlc, .xlm, .xlw</td>
    </tr>
    <tr>
      <td>Microsoft Office - OOXML - Spreadsheet</td>
      <td>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</td>
      <td>.xlsx</td>
    </tr>
  </tbody>
</table>
##### `attachment.base64_content` *(required)*

A base64 representation of the file. This can be up to **2 MB** to comply with calendar server limits.

#### Example base64 conversion code


```ruby
base64_value = Base64.urlsafe_encode64(
  File.read("docs/attachment.pdf", binmode: true)
)
```


```js
let base64Value = new FileReader().readAsDataURL("docs/attachment.pdf");
```


```python
import base64

with open("docs/attachment.pdf", "rb") as file:
    base64_value = base64.b64encode(file.read())
```


```php
$data = file_get_contents('docs/attachment.pdf');
$base64_value = base64_encode($data);
```


```csharp
Byte[] bytes = File.ReadAllBytes("docs/attachment.pdf");
String file = Convert.ToBase64String(bytes);
```



##### `subscriptions` *(optional)*

Attachments are virus scanned by Cronofy before being synced to calendars. Subscriptions can be used to receive a callback to the status of an attachment.

Any events created while an attachment is being scanned will be held for up to 10 seconds to see if the file is approved.
If the file is rejected or not approved in this time, the event will be written to the calendar without the attachment. Generally this is desirable to hold the time, and Cronofy will update the event with the attachment when it is approved.

However this may not be desirable for events with large numbers of attendees, as the late addition of the attachment will trigger an update to the event and email all of the attendees.

To avoid this, you can subscribe to the `attachment_approved` and `attachment_rejected` events and only call [create event](/developers/api/events/upsert-event/index.md) once the attachment has been approved.

##### `subscriptions[].type` *(optional)*

Only one value of `webhook` is supported at present.

##### `subscriptions[].uri` *(optional)*

The URI within your application you want Cronofy to send notifications to when the interaction is triggered. Must be an externally accessible HTTP or HTTPS URI.

##### `subscriptions[].interactions` *(optional)*

An array of interactions that should trigger a call to the `uri`.

##### `subscriptions[].interactions[].type` *(optional)*

The following interaction subscriptions are supported:

- `attachment_approved` - the attachment has passed all checks and is ready to be included on events.

- `attachment_rejected` - the attachment has failed a check. The request will include a body describing the failure.

### Response Parameters
##### `attachment.attachment_id`

The ID which has been assigned to this attachment. Unlike the majority of our APIs, Cronofy provides the ID for attachments to make it clearer that Attachments are **not** upserted.

##### `attachment.file_name`

The file name which will appear on events when the attachment is included.

##### `attachment.content_type`

The content type of the attachment.

##### `attachment.md5`

The MD5 hash of the file stored. This can be compared with an MD5 of your file to spot any issues with the upload.



---
[Read in HTML](/developers/api/attachments/create/)