# Move resources into a folder

> Each resource (from GET .../resources) is filed under the folder; a resource of another region than the folder is not moved. Moving again to the same folder changes nothing, so a retry is safe. With validate_only, the answer tells what would move, without moving anything.

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

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

- Operation: `move_resources_to_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. |
| `folder_id` | string (uuid) | Yes | The folder. |

## 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 |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `resources` | array of object (ResourceToMove), at least 1 item, at most 200 items | Yes |  |
| `resources[].resource_type` | string (connection \| folder \| workflow \| workspace_variable \| sync \| api_proxy \| app_queue \| genie \| knowledge_base) | Yes |  |
| `resources[].resource_id` | string (uuid) | Yes | Id of the resource |
| `resources[].region` | string (besg \| usnv) | Yes |  |
| `validate_only` | boolean, default false | No | Run every check of the move and answer what would move and what would not, with why, without moving anything: a refused request answers the error the move would |

## Returns

### 200 OK

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `folder_id` | string \| null | Yes | The destination folder; None for the root |
| `moved` | array of object (MovedResource) | Yes |  |
| `moved[].resource_type` | string (connection \| folder \| workflow \| workspace_variable \| sync \| api_proxy \| app_queue \| genie \| knowledge_base) | Yes |  |
| `moved[].resource_id` | string | Yes |  |
| `moved[].region` | string (besg \| usnv) | Yes |  |
| `moved[].resource_name` | string \| null | No | The name of the resource; None when it was not found |
| `moved[].source_folder_id` | string \| null | No | The folder it was in before the move; None at the root or when it was not found |
| `failed` | array of object (ResourceNotMoved) | Yes |  |
| `failed[].resource_type` | string (connection \| folder \| workflow \| workspace_variable \| sync \| api_proxy \| app_queue \| genie \| knowledge_base) | Yes |  |
| `failed[].resource_id` | string | Yes |  |
| `failed[].region` | string (besg \| usnv) | Yes |  |
| `failed[].resource_name` | string \| null | No | The name of the resource; None when it was not found |
| `failed[].source_folder_id` | string \| null | No | The folder it was in before the move; None at the root or when it was not found |
| `failed[].msg` | string | Yes | Why this resource was not moved |

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/folders/{folder_id}/resources?region=besg" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "resources": [
    {
      "resource_type": "connection",
      "resource_id": "3f6c1d2e-8a4b-4c7d-9e21-5b6f7a8c9d01",
      "region": "besg"
    }
  ]
}'
```

## Example response (200)

```json
{
  "folder_id": "<folder_id>",
  "moved": [
    {
      "resource_type": "connection",
      "resource_id": "<resource_id>",
      "region": "besg",
      "resource_name": "<resource_name>",
      "source_folder_id": "<source_folder_id>"
    }
  ],
  "failed": [
    {
      "resource_type": "connection",
      "resource_id": "<resource_id>",
      "region": "besg",
      "resource_name": "<resource_name>",
      "source_folder_id": "<source_folder_id>",
      "msg": "<msg>"
    }
  ]
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | Bad Request | `{ "error": string, "msg": string, "field": string \| null }` |
| 403 | Forbidden | `{ "error": string, "msg": string, "field": string \| null }` |
| 404 | Not Found | `{ "error": string, "msg": string, "field": string \| null }` |
| 409 | Conflict | `{ "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)
- [Create a folder](https://docs.stacksync.com/api-reference/folders/create_folder)
- [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 to the root](https://docs.stacksync.com/api-reference/folders/move_resources_to_root_folder)