# Add User to Departments

Add a single user to one or more system-level departments at once. Departments the user is already a member of are listed under `failed`.

# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Account Operations: System admin",
    "description": "The official SeaTable API Reference (OpenAPI 3.0).",
    "version": "7.0"
  },
  "servers": [
    {
      "url": "https://{server}",
      "variables": {
        "server": {
          "default": "cloud.seatable.io"
        }
      }
    }
  ],
  "x-readme": {
    "explorer-enabled": true,
    "metrics-enabled": false,
    "proxy-enabled": false
  },
  "tags": [
    {
      "name": "Departments",
      "description": "Manage departments"
    }
  ],
  "components": {
    "securitySchemes": {
      "AccountTokenAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "This is the [Account-Token](/reference/authentication)."
      }
    },
    "schemas": {
      "username": {
        "type": "string",
        "example": "12abc456def789abc123def456abc789@auth.local"
      },
      "department_ids": {
        "type": "array",
        "description": "The IDs of the departments the user should be added to.",
        "items": {
          "type": "integer"
        },
        "example": [
          2,
          3
        ]
      }
    }
  },
  "paths": {
    "/api/v2.1/admin/address-book-v2/departments/add-to-departments/": {
      "post": {
        "tags": [
          "Departments"
        ],
        "summary": "Add User to Departments",
        "operationId": "addUserToDepartments",
        "description": "Add a single user to one or more system-level departments at once. Departments the user is already a member of are listed under `failed`.",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "department_ids"
                ],
                "properties": {
                  "email": {
                    "$ref": "#/components/schemas/username"
                  },
                  "department_ids": {
                    "$ref": "#/components/schemas/department_ids"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "AccountTokenAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "failed": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                },
                "example": {
                  "success": [
                    {
                      "id": 3,
                      "name": "Test Department",
                      "parent_id": 1,
                      "org_id": -1,
                      "id_in_org": 3
                    }
                  ],
                  "failed": [
                    {
                      "department": {
                        "id": 2,
                        "name": "Developers",
                        "parent_id": 1,
                        "org_id": -1,
                        "id_in_org": 2
                      },
                      "error_msg": "User has been in Developers"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "_id": {
    "buffer": {
      "0": 106,
      "1": 215,
      "2": 108,
      "3": 15,
      "4": 227,
      "5": 154,
      "6": 119,
      "7": 91,
      "8": 88,
      "9": 173,
      "10": 68,
      "11": 82
    }
  }
}
```