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

# Create Class

> Create a class to define any data structure you need. The class can be created by the account owner only.

#### Recipes

<AccordionGroup>
  <Accordion title="Create class">
    <Steps>
      <Step title="1. Set a name of the classs">
        Use a `name` parameter to set the name of the class.

        ```curl {5} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: c95dbdc9c72cc8e7f2367d7ef2c6d99c5e013233" \
        -d '{
          "name":"UserCustomProfile",
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="2. Use a `fields` parameter to set custom fields">
        The `fields` stores a set of unique keys each having an associated value parameter.

        ```curl {6} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: c95dbdc9c72cc8e7f2367d7ef2c6d99c5e013233" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{},
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="3. Set fields of the custom class">
        Set as many fields for a new class as you need.

        ```curl {6-11} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: c95dbdc9c72cc8e7f2367d7ef2c6d99c5e013233" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="4. Use a `permissions` parameter to set operations allowed and access levels">
        ```curl {12} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: c95dbdc9c72cc8e7f2367d7ef2c6d99c5e013233" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
          "permissions":{},
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="5. Set CRUD operations">
        Set the operations that can be performed on a record.

        Here, the `create`, `read`, and `update` operations are set.

        ```curl {13-15} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: c95dbdc9c72cc8e7f2367d7ef2c6d99c5e013233" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
          "permissions":{
            "create":{},
            "read":{},
            "update":{},
          },
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="6. Set access levels">
        Set an access level for a record.

        Here, the `open`, `not_allowed`, and `open_for_users_ids` access levels are set.

        ```curl {14,17,20} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: c95dbdc9c72cc8e7f2367d7ef2c6d99c5e013233" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
          "permissions":{
            "create":{
              "access":"open"
            },
            "read":{
              "access":"not_allowed"
            },
            "update":{
              "access":"open_for_users_ids"
            },
          },
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="7. Set IDs of users">
        Set IDs of users who can make a required operation.

        ```curl {21} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: c95dbdc9c72cc8e7f2367d7ef2c6d99c5e013233" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
          "permissions":{
            "create":{
              "access":"open"
            },
            "read":{
              "access":"not_allowed"
            },
            "update":{
              "access":"open_for_users_ids",
              "ids":"1,2"
            },
          },
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="8. As a result, the API returns a newly created class.">
        ```json theme={null}
        {
          "_id": "5ddfb849a0eb4725dfc9b0ad",
          "acl": {
            "read": {
              "access": "not_allowed"
            },
            "update": {
              "access": "open_for_users_ids",
              "users_ids": [
                "1",
                "2"
              ]
            },
            "delete": {
              "access": "owner"
            },
            "create": {
              "access": "open",
              "primary": true
            }
          },
          "application_id": 78387,
          "custom_fields": [
            {
              "name": "name",
              "type": "String"
            },
            {
              "name": "last_name",
              "type": "String"
            },
            {
              "name": "age",
              "type": "Integer"
            },
            {
              "is_array": "1",
              "name": "tags",
              "type": "String"
            }
          ],
          "name": "UserCustomProfile",
          "user_id": 91103344
        }
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Create class with API key">
    <Steps>
      <Step title="1. Use 'Authorization' header to pass API key">
        ```curl {3} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name":"UserCustomProfile",
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="2. Set a name of the classs">
        Use a `name` parameter to set the name of the class.

        ```curl {5} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name":"UserCustomProfile",
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="3. Use a `fields` parameter to set custom fields">
        The `fields` stores a set of unique keys each having an associated value parameter.

        ```curl {6} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{},
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="4. Set fields of the custom class">
        Set as many fields for a new class as you need.

        ```curl {6-11} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="5. Use a `permissions` parameter to set operations allowed and access levels">
        ```curl {12} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
          "permissions":{},
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="6. Set CRUD operations">
        Set the operations that can be performed on a record.

        Here, the `create`, `read`, and `update` operations are set.

        ```curl {13-15} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
          "permissions":{
            "create":{},
            "read":{},
            "update":{},
          },
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="7. Set access levels">
        Set an access level for a record.

        Here, the `open`, `not_allowed`, and `open_for_users_ids` access levels are set.

        ```curl {14,17,20} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
          "permissions":{
            "create":{
              "access":"open"
            },
            "read":{
              "access":"not_allowed"
            },
            "update":{
              "access":"open_for_users_ids"
            },
          },
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="8. Set IDs of users">
        Set IDs of users who can make a required operation.

        ```curl {21} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name":"UserCustomProfile",
          "fields":{
            "name":"String",
            "last_name":"String",
            "age":"Integer",
            "tags":"String_a"
          },
          "permissions":{
            "create":{
              "access":"open"
            },
            "read":{
              "access":"not_allowed"
            },
            "update":{
              "access":"open_for_users_ids",
              "ids":"1,2"
            },
          },
        }' \
        "https://api.quickblox.com/class.json"
        ```
      </Step>

      <Step title="9. As a result, the API returns a newly created class.">
        ```json theme={null}
        {
          "_id": "5ddfb849a0eb4725dfc9b0ad",
          "acl": {
            "read": {
              "access": "not_allowed"
            },
            "update": {
              "access": "open_for_users_ids",
              "users_ids": [
                "1",
                "2"
              ]
            },
            "delete": {
              "access": "owner"
            },
            "create": {
              "access": "open",
              "primary": true
            }
          },
          "application_id": 78387,
          "custom_fields": [
            {
              "name": "name",
              "type": "String"
            },
            {
              "name": "last_name",
              "type": "String"
            },
            {
              "name": "age",
              "type": "Integer"
            },
            {
              "is_array": "1",
              "name": "tags",
              "type": "String"
            }
          ],
          "name": "UserCustomProfile",
          "user_id": 91103344
        }
        ```
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>

**Allowed permissions**

| Permission         | Syntax                                                                                                                      | Example                                                                               |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| Open               | permissions.\<CRUD\_operation>.access                                                                                       | permissions.read.access=open                                                          |
| Owner              | permissions.\<CRUD\_operation>.access                                                                                       | permissions.read.access=owner                                                         |
| Not allowed        | permissions.\<CRUD\_operation>.access                                                                                       | permissions.read.access=not\_allowed                                                  |
| Open for users IDs | permissions.\<CRUD\_operation>.access=open\_for\_users\_ids permissions.\<CRUD\_operation>.ids=id\_1,id\_2,id\_3,…          | permissions.update.access=open\_for\_users\_ids permissions.update.ids=3,12           |
| Open for groups    | permissions.\<CRUD\_operation>.access=open\_for\_groups permissions.\<CRUD\_operation>.groups=group\_name\_1,group\_name\_2 | permissions.delete.access=open\_for\_groups permissions.delete.groups=experience,rate |

#### Body Parameters

<ParamField body="name" type="string" required> Custom class name. </ParamField>

<ParamField body="fields" type="object">
  Custom class fields with types.
  Format: `fields.{custom_field}=<field_type>`.

  <Expandable title="fields object">
    <ParamField body="{custom_field_N}" type="string">
      Name and type of a custom field. Can be many 1..N.

      Possible plain types: `Integer`, `Float`, `String`, `Boolean`, `File`, `Date`,
      `Location` (array of \[longitude, latitude]).

      Possible array types: `Integer_a`, `Float_a`, `Boolean_a`, `String_a`.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="permissions" type="string">
  Class permissions. Format: <br />
  `permission.<CRUD_operation>.access=<value>` <br />
  `permission.<CRUD_operation>.<option>=<value>`

  CRUD operations: `create`, `read`, `update`, `delete`. <br />
  CRUD access values: `open`, `owner`, `not_allowed`, `open_for_users_ids`, `open_for_groups`. <br />
  CRUD options: `ids`, `groups`.
</ParamField>

#### Headers

<ParamField header="QB-Token" type="string" required> A user or application session token. See [Authentication](/reference/authentication) page to learn more about session tokens. Must be used either QB-Token or Authorization. </ParamField>

<ParamField header="Authorization" type="string" default="ApiKey {your_api_key}">
  API key from Dashboard. Expected format: `ApiKey {your_api_key}`. Must be used
  either QB-Token or Authorization.
</ParamField>

<ParamField header="On-Behalf-Of" type="string">
  User ID. The user ID of the user on whose behalf the request is being made.
</ParamField>

#### Responses

<AccordionGroup>
  <Accordion title="201">
    A successful response

    <ResponseField name="_id" type="string" />

    <ResponseField name="acl" type="object">
      <Expandable title="properties">
        <ResponseField name="read" type="object">
          <Expandable title="properties">
            <ResponseField name="access" type="string">
              Read access permission
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="update" type="object">
          <Expandable title="properties">
            <ResponseField name="access" type="string">
              Update access permission
            </ResponseField>

            <ResponseField name="users_ids" type="array of strings">
              Array of user IDs
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="delete" type="object">
          <Expandable title="properties">
            <ResponseField name="access" type="string">
              Delete access permission
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="create" type="object">
          <Expandable title="properties">
            <ResponseField name="access" type="string">
              Create access permission
            </ResponseField>

            <ResponseField name="primary" type="boolean" />
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="application_id" type="integer">
      The ID of the associated application
    </ResponseField>

    <ResponseField name="custom_fields" type="array">
      <Expandable title="properties">
        <ResponseField name="is_array" type="boolean" />

        <ResponseField name="name" type="string">
          Name of the custom field
        </ResponseField>

        <ResponseField name="type" type="string">
          Type of the custom field
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="name" type="string">
      Name of the resource
    </ResponseField>

    <ResponseField name="user_id" type="integer">
      The ID of the associated user
    </ResponseField>
  </Accordion>

  <Accordion title="403">
    An error response

    <ResponseField name="errors" type="array of strings" />
  </Accordion>

  <Accordion title="422">
    An error response

    <Expandable title="Option 1">
      <ResponseField name="custom_fields" type="array of strings" />
    </Expandable>

    <Expandable title="Option 2">
      <ResponseField name="name" type="array of strings" />
    </Expandable>

    <Expandable title="Option 3">
      <ResponseField name="acl" type="array of strings" />
    </Expandable>

    <Expandable title="Option 4">
      <ResponseField name="base" type="array of strings" />
    </Expandable>
  </Accordion>
</AccordionGroup>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST \
  -H "Content-Type: application/json" \
  -H "QB-Token: c95dbdc9c72cc8e7f2367d7ef2c6d99c5e013233" \
  -d '{
    "name":"UserCustomProfile",
    "fields":{
      "name":"String",
      "last_name":"String",
      "age":"Integer",
      "tags":"String_a"
    },
    "permissions":{
      "create":{
        "access":"open"
      },
      "read":{
        "access":"not_allowed"
      },
      "update":{
        "access":"open_for_users_ids",
        "ids":"1,2"
      }
    }
  }' \
  https://api.quickblox.com/class.json
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "_id": "5ddfb849a0eb4725dfc9b0ad",
    "acl": {
      "read": {
        "access": "not_allowed"
      },
      "update": {
        "access": "open_for_users_ids",
        "users_ids": [
          "1",
          "2"
        ]
      },
      "delete": {
        "access": "owner"
      },
      "create": {
        "access": "open",
        "primary": true
      }
    },
    "application_id": 78387,
    "custom_fields": [
      {
        "name": "name",
        "type": "String"
      },
      {
        "name": "last_name",
        "type": "String"
      },
      {
        "name": "age",
        "type": "Integer"
      },
      {
        "is_array": "1",
        "name": "tags",
        "type": "String"
      }
    ],
    "name": "UserCustomProfile",
    "user_id": 91103344
  }
  ```

  ```json 403 theme={null}
  {
    "errors": [
      "You don't have appropriate permissions to do this operation"
    ]
  }
  ```

  ```json 422 theme={null}
  {
    "name": [
      "can't be blank",
      "must contain only alphanumeric or underscore characters and begin with a letter.",
      "is too short (minimum is 3 characters)",
      "is too long (maximum is 50 characters)"
    ]
  }
  ```
</ResponseExample>
