Filter Harness Entities using Harness Tags in the API

Updated 1 month ago by Michael Cretzman

Harness provides advanced tagging features for all or your Harness Application entities (Services, Environments, Workflows, etc), as described in Assign Metadata Using Tags and Apply Filters Using Tags.

You can use Tags to search for entities, ensuring that you only return the entities tagged with a specific name and value.

In this topic:

Before You Begin

Step 1: Assign Tags to your Harness Entities

Harness Tags are name:value pairs you can add to Harness Application entities.

For instructions, see Assign Metadata Using Tags and Apply Filters Using Tags.

To see the available Tags in your Harness account, click Setup, and then click Tags Management. Each Tag pairs a name with one of more values:

Once you have Tags assigned, you can filter your API queries with them.

Step 2: Use TagFilter

TagFilter uses a Harness entity type of and the name:value pair of a Tag to filter queries:

{
services(filters: [{tag: {entityType: <EntityType>, tags: [{name: "<NAME>", value: "<VALUE>"}]}}], limit: 100) {
nodes {
name
}
}
}

The supported entity types are:

  • APPLICATION
  • ARTIFACT
  • CLOUD_PROVIDER
  • COLLABORATION_PROVIDER
  • CONNECTOR
  • DEPLOYMENT
  • ENVIRONMENT
  • INSTANCE
  • PIPELINE
  • SERVICE
  • TRIGGER
  • WORKFLOW

The tags: [{name: "<NAME>", value: "<VALUE>"}]}}] segment of the query uses the TagInput format:

name: String
value: String

You simply need to select an entity type and a Tag name:value pair.

Let's look at a query that returns all Applications using the DocExample Tag and a value of Yes.

{
services(filters: [
{
tag: {
entityType: APPLICATION,
tags: [{
name: "DocExample", value: "Yes"
}]}}], limit: 100) {
nodes {
name
createdBy {
id
}
deploymentType
}
}
}

All Applications using that Tag are returned:


How did we do?