# Create a folder

> At the root, or inside another folder of the same region (parent_folder_id). A folder_resource_id or name already used in the region of the workspace is refused with 409. With validate_only, every check runs and 204 answers, nothing is created.

Source: https://docs.stacksync.com/api-reference/folders/create_folder

`POST https://api.stacksync.com/v1/workspaces/{workspace_id}/folders`

- Operation: `create_folder`
- Resource: Folders
- Access: writes data

## Authentication

- `Authorization: Bearer <key>`: A workspace API key (workspace_…, created by a workspace owner under Workspace settings > Stacksync API) acts with editor rights on that workspace only; a user API key (user_…, created under Profile > Stacksync API) acts as that user in every workspace they belong to. POST, PUT and PATCH requests must send Content-Type: application/json. Every authentication failure answers 403.
- `Content-Type: application/json` on every request with a body.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace_id` | integer | Yes | The workspace. List the ones your key can reach with GET /v1/workspaces. |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `region` | string (besg \| usnv) | Yes | Region of the resource: besg (Europe) or usnv (United States), as GET /v1/regions lists them |

## Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string \| null | No | Makes the create retry-safe for 24 hours: a retry with the same key answers the resource the first call created, with the Idempotent-Replayed: true header, and creates nothing. 1 to 255 visible ASCII characters. The same key with a different request answers 422; while the first call still runs, 409. |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `folder_name` | string, 1 to 255 characters | Yes |  |
| `folder_resource_id` | string \| null, pattern `^[a-z0-9_]{1,60}$` | No | A unique, readable id of the folder in the region of the workspace (lowercase letters, digits and _); derived from the name when absent |
| `parent_folder_id` | string (uuid) \| null | No | The folder to create it in; the root when absent |
| `validate_only` | boolean, default false | No | Run every check of the write and answer 204 without writing: a refused write answers the error the write would |

## Returns

### 201 Created

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `folder_id` | string | Yes |  |
| `folder_name` | string | Yes |  |
| `folder_resource_id` | string | Yes |  |
| `parent_folder_id` | string \| null | Yes | The folder it is in; None at the root |
| `region` | string (besg \| usnv) | Yes |  |

### 204 No Content

No body.

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/folders?region=besg" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "folder_name": "<folder_name>"
}'
```

## Example response (201)

```json
{
  "folder_id": "<folder_id>",
  "folder_name": "<folder_name>",
  "folder_resource_id": "<folder_resource_id>",
  "parent_folder_id": "<parent_folder_id>",
  "region": "besg"
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | Bad Request | `{ "error": string, "msg": string, "field": string \| null }` |
| 403 | Forbidden | `{ "error": string, "msg": string, "field": string \| null }` |
| 409 | Conflict | `{ "error": string, "msg": string, "field": string \| null }` |
| 422 | Unprocessable Content | `{ "error": string, "msg": string, "field": string \| null }` |

## Related

- [API Reference overview](https://docs.stacksync.com/api-reference): base URLs, regions, pagination, idempotency and errors
- [Authentication](https://docs.stacksync.com/api-reference/authentication): API keys and the 403 answers
- OpenAPI document: https://docs.stacksync.com/openapi.json
- [List the resources in a folder](https://docs.stacksync.com/api-reference/folders/list_folder_resources)
- [List the resources at the root](https://docs.stacksync.com/api-reference/folders/list_root_folder_resources)
- [Get a folder](https://docs.stacksync.com/api-reference/folders/get_folder)
- [Get the folder tree](https://docs.stacksync.com/api-reference/folders/get_folder_tree)
- [Rename a folder](https://docs.stacksync.com/api-reference/folders/update_folder)
- [Delete an empty folder](https://docs.stacksync.com/api-reference/folders/delete_folder)
- [Move resources into a folder](https://docs.stacksync.com/api-reference/folders/move_resources_to_folder)
- [Move resources to the root](https://docs.stacksync.com/api-reference/folders/move_resources_to_root_folder)