# 标签 API

<Aside type="note">
要为 HWID 和 UserID 设置标签值，请使用 Device API 中的 [/setTags](/zh/developer/api-reference/device-api#settags) 方法。
</Aside>

## addTag

`POST` `https://api.pushwoosh.com/json/1.3/addTag`

在您的账户中创建一个标签。

#### 请求正文

| 名称 | 类型 | 描述 |
| ------------------------------------------ | ------- | -------------------------------------------------------------------------------------------------------- |
| auth\* | string | 来自 Pushwoosh Control Panel 的 [API access token](/zh/developer/api-reference/api-identifiers/#api-access-token)。 |
| tag\* | object | 标签参数。 |
| tag.name\* | string | 标签名称。 |
| tag.type\* | integer | 标签类型。请参阅下面的可能值。 |
| tag.user\_specific | boolean | 当为 `true` 时，标签值存储在用户级别，并通过 UserID 设置时在用户的所有设备之间共享。当为 `false`（默认值）时，标签是设备级别的，并按 HWID 设置。 |

<Tabs>
<TabItem label="200">
```json
{
  "status_code": 200,
  "status_message": "OK",
  "response": {
    "result": true
  }
}
```
</TabItem>
</Tabs>

```json title="示例"
{
  "request": {
    "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh Control Panel 的 API access token
    "tag": {
      "name": "TAG_NAME",           // 必需。
      "type": 1,                    // 必需。请参阅下面的可能值
      "user_specific": false        // 可选。true = 用户级标签（在所有设备间共享）；false = 设备级标签（默认）
    }
  }
}
```

**可能的标签值类型：**

*   1 - 整数
*   2 - 字符串
*   3 - 列表
*   4 - 日期
*   5 - 布尔值
*   6 - 小数。例如：19.95
*   7 - 版本。例如："1.0.0.0"

## deleteTag

`POST` `https://api.pushwoosh.com/json/1.3/deleteTag`

从数据库中完全删除一个标签及其所有相关信息。

#### 请求正文

| 名称 | 类型 | 描述 |
| ------------------------------------------ | ------ | ---------------------------------------------- |
| auth\* | string | 来自 Pushwoosh Control Panel 的 [API access token](/zh/developer/api-reference/api-identifiers/#api-access-token)。 |
| tag\* | object | 标签参数。 |
| tag.name\* | string | 要删除的 [tag](/zh/developer/api-reference/api-identifiers/#tag) 的名称。 |

<Tabs>
<TabItem label="200">
```json
{
  "status_code": 200,
  "status_message": "OK",
  "response": {
    "result": true
  }
}
```
</TabItem>
</Tabs>

```json title="示例"
{
  "request": {
    "auth": "yxoPUlwqm…………pIyEX4H", // 必需。来自 Pushwoosh Control Panel 的 API access token
    "tag": {
      "name": "TAG_NAME"            // 必需。要删除的标签名称
    }
  }
}
```

## listTags

`POST` `https://api.pushwoosh.com/json/1.3/listTags`

检索账户上的标签列表。

#### 请求正文

| 名称 | 类型 | 描述 |
| -------------------------------------- | ------ | ---------------------------------------------- |
| auth\* | string | 来自 Pushwoosh Control Panel 的 [API access token](/zh/developer/api-reference/api-identifiers/#api-access-token)。 |

<Tabs>
<TabItem label="200">
```json
{
  "status_code": 200,
  "status_message": "OK", 
  "response": {
    "tags": [{
      "name":"Language",
      "type":2
    }, {
      "name":"List tag",
      "type":3
    }]
  }
}
```
</TabItem>
</Tabs>

```json title="示例"
{
  "request":{
    "auth": "yxoPUlwqm…………pIyEX4H" // 来自 Pushwoosh Control Panel 的 API access token
  }
} 
```

**标签类型**：

*   1 - 整数
*   2 - 字符串
*   3 - 列表
*   4 - 日期
*   5 - 布尔值
*   6 - 小数。例如：19.95
*   7 - 版本。例如："1.0.0.0"