> For the complete documentation index, see [llms.txt](https://developers.getafile.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.getafile.io/files/create-a-file.md).

# Create a File

**Please note:** If you include "filename" and "fileversion" elements, a new version will be created and served.

<mark style="color:green;">`POST`</mark> `https://{region}.getafile.io/api/v1/teams/:team_id/file`

This endpoint allows you to create a file.

#### Path Parameters

<table><thead><tr><th width="301">Name</th><th width="151">Type</th><th>Description</th></tr></thead><tbody><tr><td>team_id<mark style="color:red;">*</mark></td><td>integer</td><td>ID of the team</td></tr></tbody></table>

#### Request Body

<table><thead><tr><th>Name</th><th width="150">Type</th><th>Description</th></tr></thead><tbody><tr><td>description<mark style="color:red;">*</mark></td><td>string</td><td>Description of the file for social sharing</td></tr><tr><td>published<mark style="color:red;">*</mark></td><td>integer</td><td>Published: 0 or 1</td></tr><tr><td>type<mark style="color:red;">*</mark></td><td>string</td><td>Type of File (image, document, video)</td></tr><tr><td>name<mark style="color:red;">*</mark></td><td>string</td><td>Reference name for the File</td></tr><tr><td>url<mark style="color:red;">*</mark></td><td>string</td><td>URL where the FIle can be accessed</td></tr><tr><td>domain_id<mark style="color:red;">*</mark></td><td>string</td><td>ID of the Domain</td></tr><tr><td>path_id<mark style="color:red;">*</mark></td><td>integer</td><td>ID of the File Path</td></tr><tr><td>fileversion</td><td>string</td><td>Base64 file data for the first version</td></tr><tr><td>fileversion_url</td><td>string</td><td>URL of a file to use as the first version. It must be a publicly accessible URL.</td></tr><tr><td>filename</td><td>string</td><td>Name of the file for the first version</td></tr><tr><td>ips</td><td>string</td><td>Restrict access to the File to IP addresses: eg. xxx.xx.xxx.xxx, xx.xxx.xx.x</td></tr><tr><td>password</td><td>string</td><td>Password protect the File</td></tr><tr><td>download_only<mark style="color:red;">*</mark></td><td>integer</td><td>This forces the file to always be downloaded: 0 or 1</td></tr><tr><td>domaincustom<mark style="color:red;">*</mark></td><td>array</td><td>An array of custom domain IDs</td></tr><tr><td>tags<mark style="color:red;">*</mark></td><td>array</td><td>An array of tags to attach to the file</td></tr><tr><td>optimizer_enabled<mark style="color:red;">*</mark></td><td>number</td><td>Optimize file versions (only applies to file type "image"): 0 or 1</td></tr><tr><td>optimizer_quality<mark style="color:red;">*</mark></td><td>number</td><td>Desired image quality after optimizing: Min 10, Max 100</td></tr><tr><td>serving_type<mark style="color:red;">*</mark></td><td>string</td><td>The type of content to serve.<br>Values:<br><strong>file:</strong> Uploaded files<br><strong>content:</strong> File content will be managed in the Getafile code editor (Javascript / CSS only).</td></tr><tr><td>content</td><td>string</td><td>The Javascript / CSS content of the first version when the serving type is <strong>content</strong></td></tr><tr><td>external_id</td><td>string</td><td>External ID from another platform for reference</td></tr><tr><td>filereferrer</td><td>array</td><td>An array of <a href="/pages/tKd17mGsVICTwGIFCT5E">referrer</a> IDs</td></tr></tbody></table>

{% tabs %}
{% tab title="201 File created successfully." %}

```json
{
    "id": 64,
    "user_id": 1,
    "domain_id": 8,
    "name": "Test",
    "path_id": null,
    "tags": null,
    "url": "test",
    "fullurl": "test",
    "published": 1,
    "type": "document",
    "discoverable": 0,
    "password": null,
    "ips": null,
    "external_id": null,
    "created_at": "2020-10-04T06:01:11.000Z",
    "updated_at": "2020-10-04T06:01:11.000Z",
    "uri": "https://sandbox-getafile-online.getafile.online/test",
    "statusping": 1,
    "statusping_config": {
      "retries": 3,
      "retries_pause": 3,
      "emails": ["test@example.com"],
    },
    "serving_type": "file",
    "content": null
}
```

{% endtab %}

{% tab title="400 There was an issue with the JSON payload." %}

```
[
    {
        "message": "That URL is already in use for this domain",
        "field": "url",
        "validation": "checkFileUrl"
    }
]
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers.getafile.io/files/create-a-file.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
