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

> Create a child record.

#### Recipes

<AccordionGroup>
  <Accordion title="Create child record 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": "Bob"
        }'\
        https://api.quikblox.com/data/user/617817b94dd9626e64022fdd/friends.json
        ```
      </Step>

      <Step title="2. Set record fields.">
        You can set as many fields as you need for a new child record.

        ```curl {5} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name": "Bob"
        }'\
        https://api.quikblox.com/data/user/617817b94dd9626e64022fdd/friends.json
        ```
      </Step>

      <Step title="3. Set a parent class, parent record ID, and child class name.">
        Specify the parent class name, parent record ID, and child class name in the URL.

        Here, the parent class is `user`, the parent record ID is `617817b94dd9626e64022fdd`, and the child class is `friends`.

        ```curl {7} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "Authorization: ApiKey 28irlNAGasWDSupO9Vw0BBMZfuHrAUYKpmroS9yBORI" \
        -d '{
          "name": "Bob"
        }'\
        https://api.quikblox.com/data/user/617817b94dd9626e64022fdd/friends.json
        ```
      </Step>

      <Step title="4. As a result, the API returns a newly created child record.">
        ```json theme={null}
        {
          "_id": "617819e24dd96270083a270c",
          "_parent_id": "617817b94dd9626e64022fdd",
          "created_at": 1635260898,
          "name": "Bob",
          "updated_at": 1635260898,
          "user_id": 579,
          "permissions": {
            "read": {
              "access": "open"
            },
            "update": {
              "access": "owner"
            },
            "delete": {
              "access": "owner"
            }
          }
        }
        ```
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>

A child record type is a record that refers to another record that has already
been created, a parent. When a record is created, it is assigned a record ID.
Thus, you can create a new record, a child, and attach it to the parent record
by pointing to its ID.

#### Path Parameters

<ParamField path="class_name" type="string" required>
  A class name of the parent custom object.
</ParamField>

<ParamField path="parent_id" type="string" required>
  An ID of the parent custom object.
</ParamField>

<ParamField path="child_name" type="string" required>
  A class name of the child custom object.
</ParamField>

#### Body Parameters

<ParamField body="{custom_field_N}" type="string">
  Set value to the field defined in Custom Object class. Can be many 1..N.
</ParamField>

<ParamField body="permissions" type="string">
  Record 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`, `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="_parent_id" type="string" />

    <ResponseField name="created_at" type="integer" />

    <ResponseField name="updated_at" type="integer" />

    <ResponseField name="user_id" type="integer" />

    <ResponseField name="permissions" type="object">
      <Expandable title="properties">
        <ResponseField name="read" type="object">
          <Expandable title="properties">
            <ResponseField name="access" type="string" />
          </Expandable>
        </ResponseField>

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

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

  <Accordion title="400">
    An error response
  </Accordion>
</AccordionGroup>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST \
  -H "Content-Type: application/json" \
  -H "QB-Token: 00b4daecf2f3cc13687515977f81e3613d000335" \
  -d '{
    "name": "Bob"
  }'\
  https://api.quikblox.com/data/user/617817b94dd9626e64022fdd/friends.json
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "_id": "617819e24dd96270083a270c",
    "_parent_id": "617817b94dd9626e64022fdd",
    "created_at": 1635260898,
    "name": "Bob",
    "updated_at": 1635260898,
    "user_id": 579,
    "permissions": {
      "read": {
        "access": "open"
      },
      "update": {
        "access": "owner"
      },
      "delete": {
        "access": "owner"
      }
    }
  }
  ```

  ```json 400 theme={null}
  {}
  ```
</ResponseExample>
