sale.propertyvariant.add
Добавить вариант свойства
Описание
Метод sale.propertyvariant.add добавляет вариант значения свойства. Метод актуален только для свойств с типом ENUM.
Параметры
fields
object
обязательный
Значения полей для создания варианта значения свойства
Параметр fields
orderPropsId
sale_order_property.id
обязательный
Идентификатор свойства
name
string
обязательный
Название варианта значения свойства
value
string
обязательный
Символьный код варианта значения свойства
sort
integer
необязательный
Сортировка
description
string
необязательный
Описание варианта значения свойства
Примеры запроса
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"fields":{"name":"Красный","orderPropsId":49,"value":"red","sort":10,"description":"Описание значения для красного цвета"}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/sale.propertyvariant.add
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"fields":{"name":"Красный","orderPropsId":49,"value":"red","sort":10,"description":"Описание значения для красного цвета"},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/sale.propertyvariant.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 PropertyVariantAddResult = {
propertyVariant: {
description: string
id: number
name: string
orderPropsId: number
sort: number
value: string
}
}
try {
const response = await $b24.actions.v2.call.make<PropertyVariantAddResult>({
method: 'sale.propertyvariant.add',
params: {
fields: {
name: 'Red',
orderPropsId: 49,
value: 'red',
sort: 10,
description: 'Description of the value for the red color',
},
},
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(result.propertyVariant.id, result.propertyVariant.name, result.propertyVariant.value)
}
} 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 addPropertyVariant() {
try {
// Initialize the SDK inside a Bitrix24 frame
const $b24 = await B24Js.initializeB24Frame()
const response = await $b24.actions.v2.call.make({
method: 'sale.propertyvariant.add',
params: {
fields: {
name: 'Red',
orderPropsId: 49,
value: 'red',
sort: 10,
description: 'Description of the value for the red color',
},
},
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(result.propertyVariant.id, result.propertyVariant.name, result.propertyVariant.value)
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
}
document.addEventListener('DOMContentLoaded', addPropertyVariant)
</script>
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
fields = {
"name": "Красный",
"orderPropsId": 49,
"value": "red",
"sort": 10,
"description": "Описание значения для красного цвета",
}
try:
bitrix_response = client.sale.propertyvariant.add(
fields=fields,
).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(
'sale.propertyvariant.add',
[
'fields' => [
'name' => 'Красный',
'orderPropsId' => 49,
'value' => 'red',
'sort' => 10,
'description' => 'Описание значения для красного цвета',
],
]
);
$result = $response
->getResponseData()
->getResult();
echo 'Success: ' . print_r($result, true);
// Нужная вам логика обработки данных
processData($result);
} catch (Throwable $e) {
error_log($e->getMessage());
echo 'Error adding property variant: ' . $e->getMessage();
}
BX24.callMethod(
"sale.propertyvariant.add", {
"fields": {
"name": "Красный",
"orderPropsId": 49,
"value": "red",
"sort": 10,
"description": "Описание значения для красного цвета"
}
},
function(result) {
if (result.error()) {
console.error(result.error());
} else {
console.info(result.data());
}
}
);
require_once('crest.php');
$result = CRest::call(
'sale.propertyvariant.add',
[
'fields' => [
'name' => 'Красный',
'orderPropsId' => 49,
'value' => 'red',
'sort' => 10,
'description' => 'Описание значения для красного цвета'
]
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
// client и ctx уже созданы — см. раздел «SDK для Go»
res, err := client.Core().Call(ctx, "sale.propertyvariant.add", b24.Params{
"fields": b24.Params{
"name": "Красный",
"orderPropsId": 49,
"value": "red",
"sort": 10,
"description": "Описание значения для красного цвета",
},
})
if err != nil {
return fmt.Errorf("sale.propertyvariant.add: %w", err)
}
// Метод заворачивает ответ в объект с ключом "propertyVariant".
raw, ok := b24.Unwrap(res.Result, "propertyVariant")
if !ok {
return fmt.Errorf("в ответе нет ключа propertyVariant")
}
var item struct {
Description string `json:"description"`
ID b24.ID `json:"id"`
Name string `json:"name"`
OrderPropsID b24.ID `json:"orderPropsId"`
Sort int `json:"sort"`
Value string `json:"value"`
}
if err := json.Unmarshal(raw, &item); err != nil {
return fmt.Errorf("разбор ответа: %w", err)
}
fmt.Println(item.Description, item.ID)
Ответ
HTTP-статус: 200
{
"result":{
"propertyVariant":{
"description":"Описание значения для красного цвета",
"id":5,
"name":"Красный",
"orderPropsId":49,
"sort":10,
"value":"red"
}
},
"time":{
"start":1711629310.006284,
"finish":1711629310.334167,
"duration":0.3278830051422119,
"processing":0.024754047393798828,
"date_start":"2024-03-28T15:35:10+03:00",
"date_finish":"2024-03-28T15:35:10+03:00"
}
}
Возвращаемые данные
result
object
Корневой элемент ответа
propertyVariant
sale_order_property_variant
Объект с информацией о добавленном варианте значения свойства
time
time
Информация о времени выполнения запроса
Обработка ошибок
HTTP-статус: 400
{
"error":0,
"error_description":"Required fields: name"
}
| Код | Описание | Значение |
|---|---|---|
201550000003 |
Не найдено свойство, к которому добавляется вариант значения свойства | |
200040300020 |
Недостаточно прав для добавления варианта значения свойства | |
100 |
Не указан или пустой параметр fields |
|
0 |
Не переданы обязательные поля структуры fields |
|
0 |
Другие ошибки (например, фатальные ошибки) | |
ERROR_NO_VALUE |
Передано пустое значение символьного кода значения варианта свойства | |
ERROR_NO_NAME |
Передано пустое значение названия значения варианта свойства |

