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

# Upload Address Book

> Upload address book contacts.

#### Recipes

<AccordionGroup>
  <Accordion title="Delete contact">
    <Steps>
      <Step title="1. Use a `contacts` parameter to set an array of contact hashes">
        ```curl {5} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Ann",
              "phone": "11223334237",
              "destroy": 1
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="2. Set a name of the contact">
        Note that a name is limited to a number of signs. Min: **1**. Max: **25**.

        ```curl {7} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Ann",
              "phone": "11223334237",
              "destroy": 1
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="3. Set a phone of the contact">
        Note that a phone is limited to a number of signs. Min: **10**. Max: **15**.

        ```curl {8} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Ann",
              "phone": "11223334237",
              "destroy": 1
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="4. Specify if you want to delete a contact">
        Set a `destroy` parameter as `1` to delete a contact.

        ```curl {9} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Ann",
              "phone": "11223334237",
              "destroy": 1
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="5. Set a device identifier">
        Set a `udid` parameter to specify a user's device. If specified, a contact will be deleted for a specified device only.

        ```curl {12} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Ann",
              "phone": "11223334237",
              "destroy": 1
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="6. As a result, the API returns a response specifying that a contact was deleted.">
        ```curl theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Ann",
              "phone": "11223334237",
              "destroy": 1
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Upload address book with incorrect data">
    <Steps>
      <Step title="1. Use a `contacts` parameter to set an array of contact hashes">
        ```curl {5} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Alex"
            },
            {
              "phone": "45645645666"
            },
            {
              "name": "",
              "phone": "456456456"
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="2. Set a `name` and `phone` of the contact as separate arrays">
        Note that it's incorrect to set a `name` separately from a `phone`.

        ```curl {7, 10} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Alex"
            },
            {
              "phone": "45645645666"
            },
            {
              "name": "",
              "phone": "456456456"
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="3. Set a `name` as an empty string">
        Note that a name is limited to a number of signs. Min: **1**. Max: **255**.

        ```curl {13} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Alex"
            },
            {
              "phone": "45645645666"
            },
            {
              "name": "",
              "phone": "456456456"
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="4. Set an incorrect phone length">
        Note that a phone is limited to a number of signs. Min: **10**. Max: **15**.

        ```curl {14} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Alex"
            },
            {
              "phone": "45645645666"
            },
            {
              "name": "",
              "phone": "456456456"
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="5. As a result, the API returns a `200` status response specifying that the data were set incorreclty.">
        ```curl theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Alex"
            },
            {
              "phone": "45645645666"
            },
            {
              "name": "",
              "phone": "456456456"
            }
          ],
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Replace contacts">
    <Steps>
      <Step title="1. Use a `contacts` parameter to set an array of contact hashes">
        ```curl {5} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Howard",
              "phone": "12312312333"
            }
          ],
          "force":1,
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="2. Set a name of a contact">
        Note that a `name` is limited to a number of signs. Min: **1**. Max: **255**.

        ```curl {7} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Howard",
              "phone": "12312312333"
            }
          ],
          "force":1,
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="3. Set a phone of a contact">
        Note that a `phone` is limited to a number of signs. Min: **10**. Max: **15**.

        ```curl {8} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Howard",
              "phone": "12312312333"
            }
          ],
          "force":1,
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="4. Specify if you want to replace existing contacts with the one specified">
        Set a `force` as `1` to replace the contacts.

        ```curl {11} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Howard",
              "phone": "12312312333"
            }
          ],
          "force":1,
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="5. Set a device identifier">
        Set a `udid` parameter to specify a user's device. If specified, contacts will be replaced for a specified device only.

        ```curl {12} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Howard",
              "phone": "12312312333"
            }
          ],
          "force":1,
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="6. As a result, the API returns a responce specifying that `1` contact was created and `3` deleted.">
        ```curl theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Howard",
              "phone": "12312312333"
            }
          ],
          "force":1,
          "udid": "2222E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="Upload address book">
    <Steps>
      <Step title="1. Use a `contacts` parameter to set an array of contact hashes">
        ```curl {5} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Mike Howard",
              "phone": "463571393241"
            },
            {
              "name": "Morgan Fuller",
              "phone": "65021272571"
            }
          ],
          "udid": "A337E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

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

        ```curl {7, 11} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Mike Howard",
              "phone": "463571393241"
            },
            {
              "name": "Morgan Fuller",
              "phone": "65021272571"
            }
          ],
          "udid": "A337E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="3. Set a phone of the contact">
        Use a `phone` parameter to set a phone of the contact.

        ```curl {8, 12} theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Mike Howard",
              "phone": "463571393241"
            },
            {
              "name": "Morgan Fuller",
              "phone": "65021272571"
            }
          ],
          "udid": "A337E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>

      <Step title="4. As a result, the API returns a `200` status response specifying that the contacts were uploaded.">
        ```curl theme={null}
        curl -X POST \
        -H "Content-Type: application/json" \
        -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
        -d '{
          "contacts": [
            {
              "name": "Mike Howard",
              "phone": "463571393241"
            },
            {
              "name": "Morgan Fuller",
              "phone": "65021272571"
            }
          ],
          "udid": "A337E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
        }' \
        https://api.quickblox.com/address_book.json
        ```
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>

This API allows you to do following things:

* Upload new address book.
* Replace old address book with a new one.
* Add/delete individual contacts.
* Update existing contacts.

#### Body Parameters

<ParamField body="contacts" type="array" required>
  Contains an array of contact objects. Each contact can contain 3 keys - `phone`, `name`, and `destroy`.

  <Expandable title="object">
    <ParamField body="phone" type="string">Contact phone. Min: 10. Max: 15.</ParamField>
    <ParamField body="name" type="string">Contact name. Required only for create/update. Min: 1. Max: 255. </ParamField>
    <ParamField body="destroy" type="boolean"> Used in a case of a contact destroy. Set `destroy=1` to apply. </ParamField>
  </Expandable>
</ParamField>

<ParamField body="force" type="integer">
  Defines force rewrite mode. Set `force=1` to apply, then all previous contacts for the device context
  will be replaced by new ones.
</ParamField>

<ParamField body="udid" type="string">
  User's device identifier. If specified, all operations will be in this context. Max. length is 64 symbols.
  If the device identifier is not specified, it means that a user has one global address book across all
  their devices.
</ParamField>

#### Headers

<ParamField header="QB-Token" type="string" required> A user session token. See [Authentication](/reference/authentication) page to learn more about the session token. </ParamField>

#### Responses

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

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

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

    <ResponseField name="deleted" type="integer" />
  </Accordion>
</AccordionGroup>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST \
  -H "Content-Type: application/json" \
  -H "QB-Token: 6d59d901c1231a4d74572224b88ccbc487012bba" \
  -d '{
    "contacts": [
      {
        "name": "Mike Howard",
        "phone": "463571393241"
      },
      {
        "name": "Morgan Fuller",
        "phone": "65021272571"
      }
    ],
    "udid": "A337E8A4-80AD-8ABA-9F5D-579EFF6BACAB"
  }' \
  https://api.quickblox.com/address_book.json
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "created": 2,
    "updated": 0,
    "deleted": 0
  }
  ```
</ResponseExample>
