biconnector.source.add
Создать источник
Описание
Метод biconnector.source.add создает новый источник данных, связанный с коннектором.
Параметры
fields
object
обязательный
Объект, содержащий данные для создания нового источника. Формат объекта:
{
"field_1": "value_1",
"field_2": "value_2",
...,
"field_n": "value_n"
}
field_n— название поляvalue_n— значение поля
Параметр fields
title
string
обязательный
Название источника
description
string
необязательный
Описание источника
active
boolean
необязательный
Активность источника.
По умолчанию true
connectorId
integer
обязательный
Идентификатор коннектора, можно получить методами biconnector.connector.list или biconnector.connector.add
settings
object
обязательный
Список параметров для авторизации, передается объектом, где ключ — code параметра.
Параметры можно получить методами biconnector.connector.list или biconnector.connector.get
Примеры запроса
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"fields":{"title":"CRM Source","description":"Источник данных CRM","connectorId":123,"settings":{"login":"admin","password":"qwerty"}}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/biconnector.source.add
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"fields":{"title":"CRM Source","description":"Источник данных CRM","connectorId":123,"settings":{"login":"admin","password":"qwerty"}},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/biconnector.source.add
// This snippet is an ES module: top-level await requires type="module" or a bundler.
// $b24 is an already-initialized SDK instance (see the SDK "Get started" guide).
import { Text } from '@bitrix24/b24jssdk'
import type { B24Frame } from '@bitrix24/b24jssdk'
declare const $b24: B24Frame
// Shape of the payload returned in result (match the "response handling" section of the page)
type SourceAddResult = {
id: number
}
try {
const response = await $b24.actions.v2.call.make<SourceAddResult>({
method: 'biconnector.source.add',
params: {
fields: {
title: 'CRM Source',
description: 'CRM data source',
connectorId: 123,
settings: {
login: 'admin',
password: 'qwerty',
},
},
},
requestId: Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
} else {
const result = response.getData()!.result
console.info('Created source id:', result.id)
}
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
<!-- Load the SDK (UMD build); it is exposed as the global B24Js -->
<script src="https://unpkg.com/@bitrix24/b24jssdk@1/dist/umd/index.min.js"></script>
<script>
async function addSource() {
try {
// Initialize the SDK inside a Bitrix24 frame
const $b24 = await B24Js.initializeB24Frame()
const response = await $b24.actions.v2.call.make({
method: 'biconnector.source.add',
params: {
fields: {
title: 'CRM Source',
description: 'CRM data source',
connectorId: 123,
settings: {
login: 'admin',
password: 'qwerty',
},
},
},
requestId: B24Js.Text.getUuidRfc4122()
})
// The payload is available only on a successful response
if (!response.isSuccess) {
console.error(response.getErrorMessages().join('; '))
return
}
const result = response.getData().result
console.info('Created source id:', result.id)
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
}
document.addEventListener('DOMContentLoaded', addSource)
</script>
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
try:
bitrix_response = client.biconnector.source.add(
fields={
"title": "CRM Source",
"description": "CRM data source",
"connectorId": 123,
"settings": {
"login": "admin",
"password": "qwerty",
},
},
).response
result = bitrix_response.result
print(result)
except BitrixAPIError as error:
print(
"Ошибка Bitrix API",
f"error: {error.error}",
f"error_description: {error.error_description}",
sep="\n",
)
except BitrixSDKException as error:
print(f"Ошибка Bitrix SDK: {error.message}")
except Exception as error:
print(f"Непредвиденная ошибка: {error}")
try {
$response = $b24Service
->core
->call(
'biconnector.source.add',
[
'fields' => [
"title" => "CRM Source",
"description" => "Источник данных CRM",
"connectorId" => 123,
"settings" => [
"login" => "admin",
"password" => "qwerty"
]
]
]
);
$result = $response
->getResponseData()
->getResult();
if ($response->getError()) {
error_log($response->getError());
echo 'Error: ' . $response->getError();
} else {
echo 'Success: ' . print_r($result, true);
}
} catch (Throwable $e) {
error_log($e->getMessage());
echo 'Error adding source: ' . $e->getMessage();
}
BX24.callMethod(
'biconnector.source.add',
{
fields: {
"title": "CRM Source",
"description": "Источник данных CRM",
"connectorId": 123,
"settings": {
"login": "admin",
"password": "qwerty"
}
}
},
(result) => {
result.error() ? console.error(result.error()) : console.info(result.data());
}
);
require_once('crest.php');
$result = CRest::call(
'biconnector.source.add',
[
'fields' => [
'title' => 'CRM Source',
'description' => 'Источник данных CRM',
'connectorId' => 123,
'settings' => [
'login' => 'admin',
'password' => 'qwerty'
]
]
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
// client и ctx уже созданы — см. раздел «SDK для Go»
res, err := client.Core().Call(ctx, "biconnector.source.add", b24.Params{
"fields": b24.Params{
"title": "CRM Source",
"description": "Источник данных CRM",
"connectorId": 123,
"settings": b24.Params{
"login": "admin",
"password": "qwerty",
},
},
})
if err != nil {
return fmt.Errorf("biconnector.source.add: %w", err)
}
var item struct {
ID b24.ID `json:"id"`
}
if err := json.Unmarshal(res.Result, &item); err != nil {
return fmt.Errorf("разбор ответа: %w", err)
}
fmt.Println(item.ID)
Ответ
HTTP-статус: 200
{
"result": {
"id": 7
},
"time": {
"start": 1725013197.635808,
"finish": 1725013198.580873,
"duration": 0.9450650215148926,
"processing": 0.6822988986968994,
"date_start": "2024-08-30T12:19:57+02:00",
"date_finish": "2024-08-30T12:19:58+02:00",
"operating": 0
}
}
Возвращаемые данные
result
object
Корневой элемент ответа. Содержит поле id с идентификатором созданного источника
time
time
Информация о времени выполнения запроса
Обработка ошибок
HTTP-статус: 200
{
"error": "VALIDATION_FIELDS_NOT_PROVIDED",
"error_description": "Fields not provided."
}
| Код | Описание | Значение |
|---|---|---|
VALIDATION_FIELDS_NOT_PROVIDED |
Fields not provided. | Поля не переданы в запросе |
VALIDATION_UNKNOWN_PARAMETERS |
Unknown parameters: #LIST_OF_PARAMS# | Обнаружены неизвестные параметры: перечень |
VALIDATION_REQUIRED_FIELD_MISSING |
Field "#TITLE#" is required. | Обязательное поле #TITLE# не передано |
VALIDATION_READ_ONLY_FIELD |
Field "#TITLE#" is read only. | Поле #TITLE# доступно только для чтения и не может быть изменено |
VALIDATION_IMMUTABLE_FIELD |
Field "#TITLE#" is immutable. | Поле #TITLE# неизменяемое |
VALIDATION_INVALID_FIELD_TYPE |
Field "#TITLE#" must be of type #TYPE#. | Поле #TITLE# должно быть типа #TYPE# |
CONNECTOR_NOT_FOUND |
Connector was not found. | Коннектор не найден |
SOURCE_CREATE_CONNECTION_ERROR |
Cannot create connection. | Ошибка при создании подключения |
SOURCE_UPDATE_CONNECTION_ERROR |
Cannot update connection. | Ошибка при обновлении подключения |
BX_ERROR |
Cannot delete source. Delete all related datasets first. | Нельзя удалить источник, пока существуют связанные датасеты |

