# Create Folder

POST https://services.leadconnectorhq.com/medias/folder

Creates a new folder in the media storage

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** No scopes required.

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/medias/folder": {
      "post": {
        "summary": "Create Folder",
        "operationId": "createFolder",
        "description": "Creates a new folder in the media storage",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateFolderParams"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Returns the newly created folder object",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FolderDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "CreateFolderParams": {
        "type": "object",
        "properties": {
          "altId": {
            "type": "string",
            "description": "Location Id",
            "example": "sx6wyHhbFdRXh302LLNR"
          },
          "altType": {
            "type": "string",
            "description": "Type of entity (location only)",
            "enum": [
              "location"
            ],
            "example": "location"
          },
          "name": {
            "type": "string",
            "description": "Name of the folder to be created",
            "example": "New Folder"
          },
          "parentId": {
            "type": "string",
            "description": "ID of the parent folder (optional)",
            "example": "64af50c42d567a3b4f5989e0"
          }
        },
        "required": [
          "altId",
          "altType",
          "name"
        ],
        "title": "CreateFolderParams"
      },
      "FolderDTO": {
        "type": "object",
        "properties": {
          "altId": {
            "type": "string",
            "description": "Location identifier that owns this folder",
            "example": "sx6wyHhbFdRXh302LLNR"
          },
          "altType": {
            "type": "string",
            "description": "Type of entity that owns the folder",
            "enum": [
              "location"
            ],
            "example": "location"
          },
          "name": {
            "type": "string",
            "description": "Name of the folder",
            "example": "New Folder"
          },
          "parentId": {
            "type": "string",
            "description": "ID of the parent folder (null for root folders)",
            "example": "64af50c42d567a3b4f5989e0"
          },
          "type": {
            "type": "string",
            "description": "Type of the object (always 'folder' for folders)",
            "example": "folder"
          },
          "deleted": {
            "type": "boolean",
            "description": "Whether the folder has been deleted",
            "example": false
          },
          "pendingUpload": {
            "type": "boolean",
            "description": "Whether there are pending uploads to this folder",
            "example": false
          },
          "category": {
            "type": "string",
            "description": "Primary category of content stored in the folder",
            "example": "image"
          },
          "subCategory": {
            "type": "string",
            "description": "Sub-category of content stored in the folder",
            "example": "logo"
          },
          "isPrivate": {
            "type": "boolean",
            "description": "Whether the folder is private and not publicly accessible",
            "example": false
          },
          "relocatedFolder": {
            "type": "boolean",
            "description": "Whether the folder has been moved from its original location",
            "example": false
          },
          "migrationCompleted": {
            "type": "boolean",
            "description": "Whether the data migration process has been completed for this folder",
            "example": true
          },
          "appFolder": {
            "type": "boolean",
            "description": "Whether this is a system-generated application folder",
            "example": false
          },
          "isEssential": {
            "type": "boolean",
            "description": "Whether the folder is essential and should not be deleted",
            "example": false
          },
          "status": {
            "type": "string",
            "description": "Current status of the folder"
          },
          "lastUpdatedBy": {
            "type": "string",
            "description": "ID of the user who last updated the folder",
            "example": "user-uuid-123"
          }
        },
        "required": [
          "altId",
          "altType",
          "name",
          "type"
        ],
        "title": "FolderDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/medias/folder' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "altId": "sx6wyHhbFdRXh302LLNR",
  "altType": "location",
  "name": "New Folder",
  "parentId": "64af50c42d567a3b4f5989e0"
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "altId": "sx6wyHhbFdRXh302LLNR",
      "altType": "location",
      "name": "New Folder",
      "parentId": "64af50c42d567a3b4f5989e0"
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/medias/folder', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/medias/folder"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "altId": "sx6wyHhbFdRXh302LLNR",
    "altType": "location",
    "name": "New Folder",
    "parentId": "64af50c42d567a3b4f5989e0"
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/medias/folder',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "altId": "sx6wyHhbFdRXh302LLNR",
  "altType": "location",
  "name": "New Folder",
  "parentId": "64af50c42d567a3b4f5989e0"
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/medias/folder")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"altId\":\"sx6wyHhbFdRXh302LLNR\",\"altType\":\"location\",\"name\":\"New Folder\",\"parentId\":\"64af50c42d567a3b4f5989e0\"}")
  .asString();
```

**Go**

```go
package main

import (
  "fmt"
  "net/http"
  "io"
  "strings"
)

func main() {
  url := "https://services.leadconnectorhq.com/medias/folder"
  payload := strings.NewReader(`{
  "altId": "sx6wyHhbFdRXh302LLNR",
  "altType": "location",
  "name": "New Folder",
  "parentId": "64af50c42d567a3b4f5989e0"
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)
  fmt.Println(string(body))
}
```

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/medias/folder")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "altId": "sx6wyHhbFdRXh302LLNR",
  "altType": "location",
  "name": "New Folder",
  "parentId": "64af50c42d567a3b4f5989e0"
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "altId": "sx6wyHhbFdRXh302LLNR",
  "altType": "location",
  "name": "New Folder",
  "parentId": "64af50c42d567a3b4f5989e0"
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/medias/folder' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
