Skip to main content

Product attributes

The product attributes API allows you to create, view, update, and delete individual, or a batch, of product attributes.

Product attribute properties​

AttributeTypeDescription
idintegerUnique identifier for the resource. READ-ONLY
namestringAttribute name. MANDATORY
slugstringAn alphanumeric identifier for the resource unique to its type.
typestringType of attribute. By default only select is supported.
order_bystringDefault sort order. Options: menu_order, name, name_num and id. Default is menu_order.
has_archivesbooleanEnable/Disable attribute archives. Default is false.

Create a product attribute​

This API helps you to create a new product attribute.

POST /wp-json/wc/v3/products/attributes
curl -X POST https://example.com/wp-json/wc/v3/products/attributes \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "Color",
"slug": "pa_color",
"type": "select",
"order_by": "menu_order",
"has_archives": true
}'

Retrieve a product attribute​

This API lets you retrieve and view a specific product attribute by ID.

GET /wp-json/wc/v3/products/attributes/<id>
curl https://example.com/wp-json/wc/v3/products/attributes/1 \
-u consumer_key:consumer_secret

List all product attributes​

This API helps you to view all the product attributes.

GET /wp-json/wc/v3/products/attributes
curl https://example.com/wp-json/wc/v3/products/attributes \
-u consumer_key:consumer_secret

Available parameters​

ParameterTypeDescription
contextstringScope under which the request is made; determines fields present in response. Options: view and edit. Default is view.

Update a product attribute​

This API lets you make changes to a product attribute.

PUT /wp-json/wc/v3/products/attributes/<id>
curl -X PUT https://example.com/wp-json/wc/v3/products/attributes/1 \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"order_by": "name"
}'

Delete a product attribute​

This API helps you delete a product attribute.

DELETE /wp-json/wc/v3/products/attributes/<id>
warning

This also will delete all terms from the selected attribute.

curl -X DELETE https://example.com/wp-json/wc/v3/products/attributes/1?force=true \
-u consumer_key:consumer_secret

Available parameters​

ParameterTypeDescription
forcestringRequired to be true, as resource does not support trashing.

Batch update product attributes​

This API helps you to batch create, update and delete multiple product attributes.

note

Note: By default it's limited to up to 100 objects to be created, updated or deleted.

POST /wp-json/wc/v3/products/attributes/batch
curl -X POST https://example.com/wp-json/wc/v3/products/attributes/batch \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"create": [
{
"name": "Brand"
},
{
"name": "Publisher"
}
],
"update": [
{
"id": 2,
"order_by": "name"
}
],
"delete": [
1
]
}'