VALIDATION_ERROR' 'PropertyValidationError.NON_UNIQUE_OPTION_LABELS'

Hi!
I get the following error when trying to update a dropdown custom property on contact and customer via the API:

 body: {
 status: 'error',
 message: "Property option labels must be unique. For the property 'X' of object type 'Y' these labels are duplicated: Z",
 correlationId: 'dcc084f8-cb3f-4a7b-9704-67e00a1f54b0',
 context: [Object],
 category: 'VALIDATION_ERROR',
 subCategory: 'PropertyValidationError.NON_UNIQUE_OPTION_LABELS'
 },

Z has been a part of the dropdown X before, but was removed some time ago. I’m now trying to add it back without any luck. It works for elements that haven’t been in the list before.

The javascript for the custom code:

 const hubspot = require('@hubspot/api-client');
 const hubspotClient = new hubspot.Client({
 accessToken: process.env.access_token,
 numberOfApiCallRetries: hubspot.NumberOfRetries.Six,
 });
 const targetContactDropdownSelect = await hubspotClient.apiRequest({ 
 method: 'GET',
 path: `/crm/v3/properties/contacts/${contactPropertyName}`
 });
 targetContactDropdownSelect.body.options.push({
 label: property,
 value: objectId,
 })
 await hubspotClient.apiRequest({
 method: 'PATCH',
 path: `/crm/v3/properties/contacts/${contactPropertyName}`,
 body: {
 options: targetContactDropdownSelect.body.options
 }
 });

Hello @psl86

The label causing the issue is ‘Z’. Although you mentioned that it was removed from the list before, it seems that it still exists in the options.

you need to ensure that all option labels within the dropdown are unique. Here’s what you can do.
HubSpot API to get the current options list.

const targetContactDropdownSelect = await hubspotClient.apiRequest({ 
 method: 'GET',
 path: `/crm/v3/properties/contacts/${contactPropertyName}`
});

Insure ‘Z’ already exists in the options list. If it does, remove it.

const options = targetContactDropdownSelect.body.options;
const updatedOptions = options.filter(option => option.label !== 'Z');

Add the new option with the label ‘Z’ and the corresponding value.

updatedOptions.push({
 label: 'Z',
 value: objectId
});

Update the dropdown property with the modified options list.

await hubspotClient.apiRequest({
 method: 'PATCH',
 path: `/crm/v3/properties/contacts/${contactPropertyName}`,
 body: {
 options: updatedOptions
 }
});

Now you can add the option ‘Z’ back to the dropdown property without encountering the validation error.