# Добавление

## Добавление нового контрагента

<mark style="color:green;">`POST`</mark> `https://do.myfreshcloud.com/company/insert`

#### Request Body

| Name                                      | Type | Description |
| ----------------------------------------- | ---- | ----------- |
| company<mark style="color:red;">\*</mark> | JSON |             |

{% tabs %}
{% tab title="200: OK Стандартный объект ответа" %}

```javascript
{
  "status": "success",
  "error": null,
  "code": "0",
  "rows": 1,
  "pages": 1,
  "page": 1,
  "value": "1" 
}
```

{% endtab %}
{% endtabs %}

## JSON&#x20;

<details>

<summary>Все доступные параметры нового объекта </summary>

* **name**  - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Наименование компании</mark>
* **first\_name** - <mark style="background-color:blue;">Имя физического лица</mark>
* **last\_name** - <mark style="background-color:blue;">Фамилия физического лица</mark>
* **middle\_name** - <mark style="background-color:blue;">Отчество физического лица</mark>
* **person** - <mark style="background-color:blue;">Признак юридическое или физическое лицо \[Int] (1/2)</mark>&#x20;
* **address** - <mark style="background-color:blue;">Основной адрес</mark>&#x20;
* **country** - <mark style="background-color:blue;">Страна</mark>
* **region**  - <mark style="background-color:blue;">Регион</mark>
* **user\_id** - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Код ответственного</mark>&#x20;
* **type\_id** - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Код типа</mark>&#x20;
* **status\_id** - <mark style="background-color:blue;">Код статуса</mark>&#x20;
* **category\_id** - <mark style="background-color:blue;">Код категории</mark>
* **url** - <mark style="background-color:blue;">Вэб сайт</mark>
* **activity\_type** - <mark style="background-color:blue;">Род деятельности</mark>
* **info\_source** - <mark style="background-color:blue;">Источник информации</mark>
* **note** -  <mark style="background-color:blue;">Примечание</mark>
* **which\_site\_source -** <mark style="background-color:blue;">Web сайт источник лида</mark>
* **which\_host\_source -** <mark style="background-color:blue;">Web хост источник лида</mark>
* **which\_link\_source -** <mark style="background-color:blue;">Web ссылка перехода источник лида</mark>
* **utm\_campaign -** <mark style="background-color:blue;">UTM источник лида</mark>
* **utm\_source -** <mark style="background-color:blue;">UTM источник лида</mark>
* **utm\_medium -** <mark style="background-color:blue;">UTM источник лида</mark>
* **utm\_content -** <mark style="background-color:blue;">UTM источник лида</mark>
* **utm\_term -** <mark style="background-color:blue;">UTM источник лида</mark>

#### Contacts - <mark style="background-color:purple;">Список контактных лиц</mark>

* **first\_name** - <mark style="background-color:purple;">Имя</mark>
* **last\_name** - <mark style="background-color:purple;">Фамилия</mark>
* **post -** <mark style="background-color:purple;">Должность</mark>
* **note** - <mark style="background-color:purple;">Примечание</mark>
* **status\_id** - <mark style="background-color:purple;">Код статуса контактного лица</mark>
* **Email -** <mark style="background-color:purple;">Список emal адресов контактного лица</mark>
* **Phones** - <mark style="background-color:purple;">Список телефонов контактного лица</mark>

#### Emails - <mark style="background-color:orange;">Список email адресов контрагента</mark>

* **email** - <mark style="background-color:orange;">Email</mark>

#### Phones - <mark style="background-color:yellow;">Список телефонов контрагента</mark>

* **phone** - <mark style="background-color:yellow;">Телефон</mark>
* **descr** - <mark style="background-color:yellow;">Тип телефона</mark>

</details>

```

{
    "name" : "Apple",
    "type_id" : 1,
    "user_id" : 37,
    
    "Contacts": [
                 {
                  "first_name": "John",
                  "last_name": "Smith",
                  "post": "CEO",
                  "note": "The main decision maker",
                  "status_id": 1,
                  "Emails": [
                              {
                               "email": "John@example.com"
                              }
                            ],
                  "Phones": [
                              {
                               "phone": "+1 234 567890",
                               "descr": "mobile"
                              }
                            ]
                   } 
                 ],
        "Emails": [
                     {
                       "email": "company@example.com"
                     }
                  ],
        "Phones": [
                     {
                       "phone": "+1 123 345678",
                        "descr": "Reception"
                      }
                   ]
  }
  
 
```

{% hint style="info" %}
**Обязательные параметры**\
name (Наименование)\
type\_id (Код типа контрагента, можно взять в справчнике)\
user\_id (Код отвесвенного, можно взять пользователях)
{% endhint %}

## Пример

{% tabs %}
{% tab title="cURL" %}

```
curl --location --request POST 'https://do.myfreshcloud.com/company/insert' \
--header 'Authorization: Bearer XXXX-XXXXXXX-XXXXXXX' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name" : "Apple",
    "type_id" : 1,
    "user_id" : 37,
    
    "Contacts": [
                 {
                  "first_name": "John",
                  "last_name": "Smith",
                  "post": "CEO",
                  "note": "The main decision maker",
                  "status_id": 1,
                  "Emails": [
                              {
                               "email": "John@example.com"
                              }
                            ],
                  "Phones": [
                              {
                               "phone": "+1 234 567890",
                               "descr": "mobile"
                              }
                            ]
                   } 
                 ],
        "Emails": [
                     {
                       "email": "company@example.com"
                     }
                  ],
        "Phones": [
                     {
                       "phone": "+1 123 345678",
                        "descr": "Reception"
                      }
                   ]
  }
  '
```

{% endtab %}

{% tab title="PHP" %}

```
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://do.myfreshcloud.com/company/insert',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "name" : "Apple",
    "type_id" : 1,
    "user_id" : 37,
    
    "Contacts": [
                 {
                  "first_name": "John",
                  "last_name": "Smith",
                  "post": "CEO",
                  "note": "The main decision maker",
                  "status_id": 1,
                  "Emails": [
                              {
                               "email": "John@example.com"
                              }
                            ],
                  "Phones": [
                              {
                               "phone": "+1 234 567890",
                               "descr": "mobile"
                              }
                            ]
                   } 
                 ],
        "Emails": [
                     {
                       "email": "company@example.com"
                     }
                  ],
        "Phones": [
                     {
                       "phone": "+1 123 345678",
                        "descr": "Reception"
                      }
                   ]
  }
  ',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer XXXXX-XXXXXXX-XXXXXXXXX',
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

{% endtab %}

{% tab title="NodeJS (Request)" %}

```
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://do.myfreshcloud.com/company/insert',
  'headers': {
    'Authorization': 'Bearer XXXX-XXXXXXX-XXXXXXX',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "name": "Apple",
    "type_id": 1,
    "user_id": 37,
    "Contacts": [
      {
        "first_name": "John",
        "last_name": "Smith",
        "post": "CEO",
        "note": "The main decision maker",
        "status_id": 1,
        "Emails": [
          {
            "email": "John@example.com"
          }
        ],
        "Phones": [
          {
            "phone": "+1 234 567890",
            "descr": "mobile"
          }
        ]
      }
    ],
    "Emails": [
      {
        "email": "company@example.com"
      }
    ],
    "Phones": [
      {
        "phone": "+1 123 345678",
        "descr": "Reception"
      }
    ]
  })

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
```

{% endtab %}
{% endtabs %}

## Справочники

{% content-ref url="/pages/p3ibECb5nmfHj0yEUSon" %}
[Для контрагентов](/reference/directory/directories-company.md)
{% endcontent-ref %}

{% content-ref url="/pages/AZqUPlTdpl1jAyZMvODJ" %}
[Пользователи](/reference/users.md)
{% endcontent-ref %}

## Ответ

```
{
  "status": "success",
  "error": null,
  "code": "0",
  "rows": 1,
  "pages": 1,
  "page": 1,
  "value": "1" 
}
// value - ID идентификатор нового контрагента
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidoc.myfreshcloud.com/reference/company/add_company.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
