# Attaching and Searching for Tags Using the REST API

In the following request and response examples, please note that the field sensitive is no longer supported in the UI for tagging columns. The sensitive field remains in the API only to support back compatibility for the [legacy version of schema annotation](/products/customer-data-platform/data-workbench/databases/schema-management).

You can annotate or search databases or tables based on tags, but you must have policy-based database permissions enabled. Learn more about [access control for tags](/products/control-panel/security/tag-management/understanding-access-control-for-column-tags).

## Attach Tags to a Column

You can attach a PII tag to a host column of a table. In the following example, the tag PII id with the tag id: ff0e21db-af92-419f-b936-0c9c1601f2f7 is being attached to the *host* column of a table using `database_id:484834` and `table_id: 2767455`.

```bash
$ curl --location --request POST 'https://api-data-def-repo.treasuredata.com/v1/column-annotation/bulk?tableId=484834.2767455' \
    --header 'Authorization: TD1 123/abcdef•••••••••••••••••••••••0123456789' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "data": [
            {
                "attributes": {
                    "sensitive": false
                },
                "relationships": {
                    "annotation-type": {
                        "data": {
                            "id": "3213869e-7e13-45fc-99a7-1b039a7333a5",
                            "type": "annotation-type"
                        }
                    },
                    "column": {
                        "data": {
                            "id": "host",
                            "type": "treasure-data-column"
                        }
                    }
                },
                "type": "treasure-data-column"
            }
        ]
    }'
```

**Response Example**

```json
{
  "data": [
    {
      "id": "ff0e21db-af92-419f-b936-0c9c1601f2f7",
      "attributes": {
        "comment": "Personal information",
        "createdAt": "2022-01-13T21:24:57.321823Z",
        "sensitive": false
      },
      "relationships": {
        "annotation-type": {
          "data": {
            "type": "annotation-type",
            "id": "3213869e-7e13-45fc-99a7-1b039a7333a5",
            "name": "PII"
          }
        },
        "table": {
          "data": {
            "type": "treasure-data-table",
            "id": "484834.2767455"
          }
        },
        "column": {
          "data": {
            "type": "treasure-data-column",
            "id": "host"
          }
        },
        "created-by": {
          "data": {
            "type": "treasure-data-user",
            "id": "18174"
          }
        }
      },
      "type": "column-annotation"
    }
  ],
  "links": {
    "first": "/v1/column-annotation?filter%5BtableId%5D=484834.2767455",
    "self": "/v1/column-annotation?filter%5BtableId%5D=484834.2767455"
  },
  "meta": {
    "perPage": 1
  }
}
```

## Search Databases Using Tags

You can search databases based on tags by using tags as filters. For instance, the following example shows using the PII tag and the result shows that the PII tag is found in the table with id 607222.3276426 and at column dob in the table.

```bash
$ curl -s --request GET "https://api-data-def-repo.treasuredata.com/v1/column-annotation/lookup?annotationTypeName=PII" \
--header 'Authorization: TD1 ${123/abcdef•••••••••••••••••••••••0123456789}'
```

**Response Example**

```json
{
  "data": [
    {
      "id": "465302e6-67c0-4b33-9462-2f501c511601",
      "attributes": {
        "comment": "",
        "createdAt": "2021-09-30T07:40:01.792499Z",
        "sensitive": false
      },
      "relationships": {
        "annotation-type": {
          "data": {
            "type": "annotation-type",
            "id": "2f27b00e-9377-419e-91c3-4456598c30a8",
            "name": "PII"
          }
        },
        "table": {
          "data": {
            "type": "treasure-data-table",
            "id": "607222.3276426"
          }
        },
        "column": {
          "data": {
            "type": "treasure-data-column",
            "id": "dob"
          }
        },
        "created-by": {
          "data": {
            "type": "treasure-data-user",
            "id": "33648"
          }
        }
      },
      "type": "column-annotation"
    },
    ...
  ],
  "links": {
    "first": "/v1/column-annotation/lookup?annotationTypeName=PII",
    "self": "/v1/column-annotation/lookup?annotationTypeName=PII"
  },
  "meta": {
    "perPage": 250
  }
}
```