# Create a folder

`POST https://api.mailmasker.org/api/v1/drive/folders`

Make a new folder, at the top level or inside another.

- Who can use it: Any signed-in account
- Area: Drive
- Answers 201 Created when it works
- Page: https://developer.mailmasker.org/drive-create-folder

Folders nest as deep as you like, but two folders in the same place can't have the same name.

## Parameters

| Name | In | Required | What it is | Example |
|---|---|---|---|---|
| `name` | body | yes | The new folder's name. | `Receipts` |
| `parent_folder_id` | body | no | The folder to make it in. Leave it out, or send null, for the top level. | `7` |

## Good to know

- A missing name answers 400.
- A folder of that name already in the same place answers 409, and so does a parent folder that isn't yours.

## Examples

cURL:

```bash
curl -s -X POST 'https://api.mailmasker.org/api/v1/drive/folders' \
  -H "Authorization: Bearer $TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"name":"Receipts","parent_folder_id":7}'
```

Perl:

```perl
use Mojo::Base -strict;
use Mojo::UserAgent;

my $ua  = Mojo::UserAgent->new;
my $res = $ua->post('https://api.mailmasker.org/api/v1/drive/folders',
    { Authorization => "Bearer $ENV{TOKEN}" },
    json => { name => 'Receipts', parent_folder_id => 7 })->result;
die $res->code, ' ', ($res->json('/error') // $res->message), "\n" unless $res->is_success;
print $res->body, "\n";
```

homelab-cli:

```bash
homelab-cli drive mkdir Receipts --parent 7
```

## Response

201 Created:

```json
{ "id": 9, "name": "Receipts", "parent_folder_id": 7 }
```
