# Добавление

## Добавление новой сделки

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

#### Request Body

| Name                                   | Type | Description |
| -------------------------------------- | ---- | ----------- |
| deal<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

<details>

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

* **name**  - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Наименование компании</mark>
* company\_id - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Код контрагента</mark>
* type\_id - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Код типа сделки</mark>
* status\_id - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Код статуса сделки</mark>
* user\_id - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Код ответственного за сделку</mark>&#x20;
* sum - <mark style="background-color:blue;">Сумма сделки</mark>
* date\_start - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Дата начала</mark>
* date\_finish - <mark style="color:green;">\*</mark> <mark style="background-color:blue;">Дата завершения</mark>
* note - <mark style="background-color:blue;">Примечание к сделке</mark>
* Goods - <mark style="background-color:green;">Список товарных позиций</mark><br>

</details>

```

{
   "name":"test-deal-API",
   "company_id":1,
   "type_id":1,
   "status_id":5,
   "user_id":37,
   "sum":100,
   "date_start":"2022-01-21",
   "date_finish":"2022-01-22",
   "note":"test-Note",
   
    "Goods" : [{
           "goods_id" : 0,
           "discription" : "test-good-API",
           "code" : "0000001",
           "price" : 2000,
           "discount" : 0,
           "qnt" : 1,
           "note" : "test-note-API"
         }]
}
```

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

## Пример

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

```
curl --location --request POST 'https://do.myfreshcloud.com/deal/insert' \
--header 'Authorization: Bearer XXXX-XXXXXXX-XXXXXXX \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "test-deal-API",
    "company_id": 1,
    "type_id": 1,
    "status_id": 5,
    "user_id": 37,
    "sum": 100,
    "date_start": "2022-01-21",
    "date_finish": "2022-01-22",
    "note": "test-Note",
    "Goods": [
        {
            "goods_id": 0,
            "discription": "test-good-API",
            "code": "0000001",
            "price": 2000,
            "discount": 0,
            "qnt": 1,
            "note": "test-note-API"
        }
    ]
}'
```

{% endtab %}

{% tab title="PHP" %}

```
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://do.myfreshcloud.com/deal/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": "test-deal-API",
    "company_id": 1,
    "type_id": 1,
    "status_id": 5,
    "user_id": 37,
    "sum": 100,
    "date_start": "2022-01-21",
    "date_finish": "2022-01-22",
    "note": "test-Note",
    "Goods": [
        {
            "goods_id": 0,
            "discription": "test-good-API",
            "code": "0000001",
            "price": 2000,
            "discount": 0,
            "qnt": 1,
            "note": "test-note-API"
        }
    ]
}',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer XXXX-XXXXXXX-XXXXXXX',
    '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/deal/insert',
  'headers': {
    'Authorization': 'Bearer XXX-XXXXXXXX-XXXXXX',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "name": "test-deal-API",
    "company_id": 1,
    "type_id": 1,
    "status_id": 5,
    "user_id": 37,
    "sum": 100,
    "date_start": "2022-01-21",
    "date_finish": "2022-01-22",
    "note": "test-Note",
    "Goods": [
      {
        "goods_id": 0,
        "discription": "test-good-API",
        "code": "0000001",
        "price": 2000,
        "discount": 0,
        "qnt": 1,
        "note": "test-note-API"
      }
    ]
  })

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

{% endtab %}
{% endtabs %}

{% content-ref url="/pages/DiE2Qj4rWlKxztIaLzfD" %}
[Справочники](/reference/directory.md)
{% endcontent-ref %}

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

&#x20;


---

# 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/deals/dobavlenie.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.
