# 产品 - 标签 #

本节列出了所有可用于创建、编辑或以其他方式操作产品标签的 API 端点。

## 产品标签属性 ##

|   属性       |   类型   |                                     描述                                      |
| ------------ | -------- | ---------------------------------------------------------------------------- |
| `id`         | integer  | 标签 ID（术语 ID）<i class="label label-info">只读</i>                       |
| `name`       | string   | 标签名称 <i class="label label-info">必需</i>                                |
| `slug`       | string   | 标签别名                                                                     |
| `description`| string   | 标签描述                                                                     |
| `count`      | integer  | 显示此标签下的产品数量 <i class="label label-info">只读</i>                  |

## 创建产品标签 ##

此 API 帮助您创建一个新的产品标签。

### HTTP 请求 ###

<div class="api-endpoint">
	<div class="endpoint-data">
		<i class="label label-post">POST</i>
		<h6>/wc-api/v3/products/tags</h6>
	</div>
</div>

> 如何创建产品标签的示例：

```shell
curl -X POST https://example.com/wc-api/v3/products/tags \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "product_tag": {
    "name": "Leather Shoes"
  }
}'
```

```javascript
var data = {
  product_tag: {
    name: 'Leather Shoes'
  }
};

WooCommerce.post('products/tags', data, function(err, data, res) {
  console.log(res);
});
```

```php
<?php
$data = [
    'product_tag': [
        'name' => 'Leather Shoes'
    ]
];

print_r($woocommerce->post('products/tags', $data));
?>
```

```python
data = {
    "product_tag": {
        "name": "Leather Shoes"
    }
}

print(wcapi.post("products/tags", data).json())
```

```ruby
data = {
  product_tag: {
    name: "Leather Shoes"
  }
}

woocommerce.post("products/tags", data).parsed_response
```

> JSON 响应示例：

```json
{
  "product_tag": {
    "id": 37,
    "name": "Leather Shoes",
    "slug": "leather-shoes",
    "description": "",
    "count": 0
  }
}
```

<aside class="notice">
	此端点自 WooCommerce 2.5 版本引入。
</aside>

## 查看产品标签 ##

此 API 允许您通过 ID 检索产品标签。

<div class="api-endpoint">
	<div class="endpoint-data">
		<i class="label label-get">GET</i>
		<h6>/wc-api/v3/products/tags/&lt;id&gt;</h6>
	</div>
</div>

```shell
curl https://example.com/wc-api/v3/products/tags/37 \
	-u consumer_key:consumer_secret
```

```javascript
WooCommerce.get('products/tags/37', function(err, data, res) {
  console.log(res);
});
```

```php
<?php print_r($woocommerce->get('products/tags/37')); ?>
```

```python
print(wcapi.get("products/tags/37").json())
```

```ruby
woocommerce.get("products/tags/37").parsed_response
```

> JSON 响应示例：

```json
{
  "product_tag": {
    "id": 37,
    "name": "Leather Shoes",
    "slug": "leather-shoes",
    "description": "",
    "count": 0
  }
}
```

<aside class="notice">
	此端点自 WooCommerce 2.5 版本引入。
</aside>

## 查看产品标签列表 ##

此 API 允许您检索所有产品标签。

<div class="api-endpoint">
	<div class="endpoint-data">
		<i class="label label-get">GET</i>
		<h6>/wc-api/v3/products/tags</h6>
	</div>
</div>

```shell
curl https://example.com/wc-api/v3/products/tags \
	-u consumer_key:consumer_secret
```

```javascript
WooCommerce.get('products/tags', function(err, data, res) {
  console.log(res);
});
```

```php
<?php print_r($woocommerce->get('products/tags')); ?>
```

```python
print(wcapi.get("products/tags").json())
```

```ruby
woocommerce.get("products/tags").parsed_response
```

> JSON 响应示例：

```json
{
  "product_tags": [
    {
      "id": 37,
      "name": "Leather Shoes",
      "slug": "leather-shoes",
      "description": "",
      "count": 0
    },
    {
      "id": 38,
      "name": "Oxford Shoes",
      "slug": "oxford-shoes",
      "description": "",
      "count": 0
    }
  ]
}
```

<aside class="notice">
	此端点自 WooCommerce 2.5 版本起引入。
</aside>

## 更新商品标签 ##

此 API 允许您修改商品标签。

### HTTP 请求 ###

<div class="api-endpoint">
	<div class="endpoint-data">
		<i class="label label-put">PUT</i>
		<h6>/wc-api/v3/products/tags/&lt;id&gt;</h6>
	</div>
</div>

```shell
curl -X PUT https://example.com/wc-api/v3/products/tags/37 \
	-u consumer_key:consumer_secret \
	-H "Content-Type: application/json" \
	-d '{
  "product_tag": {
    "description": "Genuine leather."
  }
}'
```

```javascript
var data = {
  product_tag: {
    description: 'Genuine leather.'
  }
};

WooCommerce.put('products/tags/37', data, function(err, data, res) {
  console.log(res);
});
```

```php
<?php
$data = [
    'product_tag': [
        'description': 'Genuine leather.'
    ]
];

print_r($woocommerce->put('products/tags/37', $data));
?>
```

```python
data = {
    "product_tag": {
        "description": "Genuine leather."
    }
}

print(wcapi.put("products/tags/37", data).json())
```

```ruby
data = {
  product_tag: {
    description: "Genuine leather."
  }
}

woocommerce.put("products/tags/37", data).parsed_response
```

> JSON 响应示例：

```json
{
  "product_tag": {
    "id": 37,
    "name": "Leather Shoes",
    "slug": "leather-shoes",
    "description": "Genuine leather.",
    "count": 0
  }
}
```

<aside class="notice">
	此端点自 WooCommerce 2.5 版本引入。
</aside>

## 删除商品标签 ##

此 API 可帮助您删除商品标签。

### HTTP 请求 ###

<div class="api-endpoint">
	<div class="endpoint-data">
		<i class="label label-delete">DELETE</i>
		<h6>/wc-api/v3/products/tags/&lt;id&gt;</h6>
	</div>
</div>

```shell
curl -X DELETE https://example.com/wc-api/v3/products/tags/37 \
	-u consumer_key:consumer_secret
```

```javascript
WooCommerce.delete('products/tags/37', function(err, data, res) {
  console.log(res);
});
```

```php
<?php print_r($woocommerce->delete('products/tags/37')); ?>
```

```python
print(wcapi.delete("products/tags/37").json())
```

```ruby
woocommerce.delete("products/tags/37").parsed_response
```

> JSON 响应示例：

```json
{
  "message": "Deleted product_tag"
}
```

<aside class="notice">
	此端点自 WooCommerce 2.5 版本引入。
</aside>