sale.propertyvariant.update
Обновить поля варианта свойства
Описание
Метод sale.propertyvariant.update обновляет вариант значения свойства. Метод актуален только для свойств с типом ENUM.
Параметры
id
sale_order_property_variant.id
обязательный
Идентификатор варианта значения свойства
fields
object
обязательный
Значения полей для обновления варианта значения свойств
Параметр fields
name
string
обязательный
Название варианта значения свойства
value
string
обязательный
Значение (код) варианта значения свойства
sort
integer
необязательный
Сортировка
description
string
необязательный
Описание варианта значения свойства
Примеры запроса
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"id":5,"fields":{"name":"Красный","value":"red","sort":10,"description":"Новое описание значения для красного цвета"}}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/sale.propertyvariant.update
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"id":5,"fields":{"name":"Красный","value":"red","sort":10,"description":"Новое описание значения для красного цвета"},"auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/sale.propertyvariant.update
// 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 PropertyVariantUpdateResult = {
propertyVariant: {
description: string
id: number
name: string
orderPropsId: number
sort: number
value: string
}
}
try {
const response = await $b24.actions.v2.call.make<PropertyVariantUpdateResult>({
method: 'sale.propertyvariant.update',
params: {
id: 5,
fields: {
name: 'Red',
value: 'red',
sort: 10,
description: 'New description for the red color value',
},
},
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)
}
} 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 updatePropertyVariant() {
try {
// Initialize the SDK inside a Bitrix24 frame
const $b24 = await B24Js.initializeB24Frame()
const response = await $b24.actions.v2.call.make({
method: 'sale.propertyvariant.update',
params: {
id: 5,
fields: {
name: 'Red',
value: 'red',
sort: 10,
description: 'New description for the red color value',
},
},
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)
} catch (error) {
// Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
console.error(error)
}
}
document.addEventListener('DOMContentLoaded', updatePropertyVariant)
</script>
from b24pysdk.errors import BitrixAPIError, BitrixSDKException
fields = {
"name": "Красный",
"value": "red",
"sort": 10,
"description": "Новое описание значения для красного цвета",
}
try:
bitrix_response = client.sale.propertyvariant.update(
bitrix_id=5,
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.update',
[
'id' => 5,
'fields' => [
'name' => 'Красный',
'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 updating property variant: ' . $e->getMessage();
}
BX24.callMethod(
"sale.propertyvariant.update", {
"id": 5,
"fields": {
"name": "Красный",
"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.update',
[
'id' => 5,
'fields' => [
'name' => 'Красный',
'value' => 'red',
'sort' => 10,
'description' => 'Новое описание значения для красного цвета'
]
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
// client и ctx уже созданы — см. раздел «SDK для Go»
res, err := client.Core().Call(ctx, "sale.propertyvariant.update", b24.Params{
"id": 5,
"fields": b24.Params{
"name": "Красный",
"value": "red",
"sort": 10,
"description": "Новое описание значения для красного цвета",
},
})
if err != nil {
return fmt.Errorf("sale.propertyvariant.update: %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":1711630589.257634,
"finish":1711630589.527446,
"duration":0.26981210708618164,
"processing":0.010741949081420898,
"date_start":"2024-03-28T15:56:29+03:00",
"date_finish":"2024-03-28T15:56:29+03:00"
}
}
Возвращаемые данные
result
object
Корневой элемент ответа
propertyVariant
sale_order_property_variant
Объект с информацией об обновленном варианте значения свойства
time
time
Информация о времени выполнения запроса
Обработка ошибок
HTTP-статус: 400
{
"error":0,
"error_description":"Required fields: name"
}
| Код | Описание | Значение |
|---|---|---|
201540400001 |
Обновляемый вариант значения свойства не найден | |
200040300020 |
Недостаточно прав для обновления варианта значения свойства | |
100 |
Не указан параметр id |
|
100 |
Не указан или пустой параметр fields |
|
0 |
Не переданы обязательные поля структуры fields |
|
0 |
Другие ошибки (например, фатальные ошибки) | |
ERROR_NO_VALUE |
Передано пустое значение символьного кода значения варианта свойства | |
ERROR_NO_NAME |
Передано пустое значение названия значения варианта свойства |

