Create Custom Attribute
The sample use case is to create a custom attribute with the with the following properties:
- •The custom attribute must be named Region.
- •The custom attribute must be of data type string.
- •The boost value for the custom attribute must be Medium.
- •The custom attribute can have multiple values.
- •You must be able to search in the catalog using the custom attribute.
- •You must be able to sort the catalog search results based on the custom attribute.
- •The custom attribute must appear in suggestions.
You can use the REST API and create the custom reference attribute in one of the following ways:
- Using Java code and the Bundled Java Client
public String createRegionCustomAttribute() throws ApiException {
AttributesRequest attributes = new AttributesRequest()
.addItemsItem(new AttributePostRequest()
.name("Region")
.dataTypeId("core.String")
.boost(AttributePostRequest.BoostEnum.MEDIUM)
.multivalued(true)
.searchable(true)
.sortable(true)
.suggestable(true));
AttributesResponse response = this.api.catalogModelsAttributesPost(attributes);
AttributeResponse createdAttribute = response.getItems().get(0);
// Unique id is created by the system
return createdAttribute.getId();
}
}
}
- Using Curl
curl -X POST --header "Accept: application/json" --header "Content-Type: application/json" -d "{
\"items\": [
{
\"boost\": \"MEDIUM\",
\"name\": \"Region\",
\"dataTypeId\": \"core.String\",
\"multivalued\": true,
\"suggestable\": true,
\"sortable\": true,
\"searchable\": true,
\"facetable\": false,
\"classes\": []
}
]
}" "http://localhost:13000/2/catalog/models/attributes