> ## Documentation Index
> Fetch the complete documentation index at: https://developer.rocket.chat/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Role

> <div style="text-align: center; margin: 1rem 0 1rem 0;"><img src="https://raw.githubusercontent.com/RocketChat/Rocket.Chat-Open-API/main/images/premium.svg" alt="Premium tag" style="display: block; margin: auto;"></div>

Create a new <a href='https://docs.rocket.chat/docs/roles-in-rocketchat' target='_blank'>role</a> in the workspace. See <a href='https://docs.rocket.chat/v1/docs/custom-roles' target='_blank'>Custom Roles</a> for further information.

* You can't create new roles with the same name as existing roles. For example, it is not possible to create a new role with the name `admin`.
* The scope can either be `Users`(user level) or `Subscriptions`(room level).
* Permission required: `access-permissions`

### Changelog
| Version      | Description |
| ---------------- | ------------|
|6.0.0            | Moved to Enterprise plan.       |
|3.15.0            | The endpoint is no longer used to update roles.       |
|0.70.0            | Added       |

## OpenAPI

````json POST /api/v1/roles.create
{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "User Management"
  },
  "servers": [
    {
      "url": "https://apiexplorer.support.rocket.chat"
    }
  ],
  "tags": [
    {
      "name": "LDAP"
    },
    {
      "name": "Permissions"
    },
    {
      "name": "Roles"
    },
    {
      "name": "Users"
    }
  ],
  "paths": {
    "/api/v1/roles.create": {
      "post": {
        "tags": [
          "Roles"
        ],
        "summary": "Create Role",
        "description": "<div style=\"text-align: center; margin: 1rem 0 1rem 0;\"><img src=\"https://raw.githubusercontent.com/RocketChat/Rocket.Chat-Open-API/main/images/premium.svg\" alt=\"Premium tag\" style=\"display: block; margin: auto;\"></div>\n\nCreate a new <a href='https://docs.rocket.chat/docs/roles-in-rocketchat' target='_blank'>role</a> in the workspace. See <a href='https://docs.rocket.chat/v1/docs/custom-roles' target='_blank'>Custom Roles</a> for further information.\n\n* You can't create new roles with the same name as existing roles. For example, it is not possible to create a new role with the name `admin`.\n* The scope can either be `Users`(user level) or `Subscriptions`(room level).\n* Permission required: `access-permissions`\n\n### Changelog\n| Version      | Description |\n| ---------------- | ------------|\n|6.0.0            | Moved to Enterprise plan.       |\n|3.15.0            | The endpoint is no longer used to update roles.       |\n|0.70.0            | Added       |",
        "operationId": "post-api-v1-roles.create",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "description": "Enter the new role's name.",
                    "example": "newRole"
                  },
                  "scope": {
                    "type": "string",
                    "description": "The new role's scope. The scope can either be Users (user level) or Subscriptions (room level). The default value is `Users`.",
                    "example": "Subscriptions"
                  },
                  "description": {
                    "type": "string",
                    "description": "Enter a description for the new role.",
                    "example": "Role description"
                  },
                  "mandatory2fa": {
                    "type": "boolean",
                    "description": "Whether the role should have a mandatory 2FA. The default value is `false`. If set to true, users assigned to this role are prompted to enter a 2FA code for certain activities.",
                    "default": "false"
                  }
                },
                "required": [
                  "name"
                ]
              },
              "examples": {
                "Example 1": {
                  "value": {
                    "name": "Test Role",
                    "scope": "Users",
                    "description": "Testing Role for API",
                    "mandatory2fa": "false"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "role": {
                      "type": "object",
                      "properties": {
                        "_id": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        },
                        "scope": {
                          "type": "string"
                        },
                        "description": {
                          "type": "string"
                        },
                        "protected": {
                          "type": "boolean"
                        },
                        "mandatory2fa": {
                          "type": "boolean"
                        },
                        "_updatedAt": {
                          "type": "string"
                        }
                      }
                    },
                    "success": {
                      "type": "boolean"
                    }
                  }
                },
                "examples": {
                  "Success Example": {
                    "value": {
                      "role": {
                        "_id": "646c431fa8c3a3ba32d0e1c4",
                        "name": "support1",
                        "scope": "Subscriptions",
                        "description": "Role support tier 1",
                        "protected": "false",
                        "mandatory2fa": "false",
                        "_updatedAt": "2023-05-23T04:37:51.161Z"
                      },
                      "success": "true"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "error": {
                      "type": "string"
                    },
                    "errorType": {
                      "type": "string"
                    }
                  }
                },
                "examples": {
                  "Example 1": {
                    "value": {
                      "success": "false",
                      "error": "The role properties are invalid. [error-invalid-role-properties]",
                      "errorType": "error-invalid-role-properties"
                    }
                  },
                  "Example 2": {
                    "value": {
                      "success": "false",
                      "error": "Role name already exists [error-duplicate-role-names-not-allowed]",
                      "errorType": "error-duplicate-role-names-not-allowed"
                    }
                  },
                  "Example 3": {
                    "value": {
                      "success": "false",
                      "error": "Accessing permissions is not allowed [error-action-not-allowed]",
                      "errorType": "error-action-not-allowed"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/authorizationError"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/UserId"
          },
          {
            "$ref": "#/components/parameters/Auth-Token"
          }
        ]
      }
    }
  },
  "components": {
    "responses": {
      "authorizationError": {
        "description": "Unauthorized",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            },
            "examples": {
              "Authorization Error": {
                "value": {
                  "status": "error",
                  "message": "You must be logged in to do this."
                }
              }
            }
          }
        }
      }
    },
    "parameters": {
      "UserId": {
        "name": "X-User-Id",
        "in": "header",
        "description": "The authenticated user ID.",
        "required": "true",
        "schema": {
          "type": "string"
        },
        "example": "rbAXPnMktTFbNpwtJ"
      },
      "Auth-Token": {
        "name": "X-Auth-Token",
        "in": "header",
        "description": "The authenticated user token.",
        "required": "true",
        "schema": {
          "type": "string"
        },
        "example": "RScctEHSmLGZGywfIhWyRpyofhKOiMoUIpimhvheU3f"
      }
    }
  }
}
````

