# Filter Object Definition V1

In the Finout Virtual Tags API documentation, the structure of the filters object can be explained by starting with simpler usage and then detailing more complex scenarios:

1. Simple Conditions Without Logical Operators:
   * Use direct condition keys for single-condition requirements.

     Example JSON:

     ```json
     {
       "to": "Asaf",
       "filters": {
         "costCenter": "AWS",
         "key": "aws_account_name",
         "displayName": "Account Name",
         "operator": "oneOf",
         "value": [
           "004a533177",
           "0371d7d3bf"
         ]
       }
     ```
2. Complex Conditions with Nested Logical Operators:
   * AND and OR keys represent logical operators for grouping multiple conditions.
   * You can nest multiple layers of AND and OR for intricate conditional logic.

     Example JSON:

     ```json
     {
       "filters": {
         "AND": [
           {
             "OR": [
               {
                 "costCenter": "AWS",
                 "key": "condition1",
                 "operator": "equals",
                 "value": "value1"
               },
               {
                 "costCenter": "AWS",
                 "key": "condition2",
                 "operator": "equals",
                 "value": "value2"
               }
             ]
           },
           {
             "costCenter": "AWS",
             "key": "condition3",
             "operator": "equals",
             "value": "value3"
           }
         ]
       }
     }
     ```

### Filter operator object definition <a href="#h_0ae7bb324e" id="h_0ae7bb324e"></a>

| Field        | Type   | Description                                                                                                                                                                                                                                                            | Example Value                                                                                                                                                                                                                                        |
| ------------ | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| *costCenter* | string | The cost center associated with the filter.                                                                                                                                                                                                                            | "AWS" , "GCP", "Kubernetes" , "Snowflake" , "Virtual Tags" , "Datadog" , "Azure" , "Custom Cost"                                                                                                                                                     |
| *operator*   | string | The comparison operator to apply for the filter (e.g., "oneOf", "equal", "greaterThan").                                                                                                                                                                               | "oneOf"                                                                                                                                                                                                                                              |
| *value*      | array  | An array of values to use the operator against.                                                                                                                                                                                                                        | \["Amazon Web Services EMEA KFIR"]                                                                                                                                                                                                                   |
| *key*        | string | <p>The key in Finout filters.</p><p>For non-unique keys or specific keys (finrichment), a transform function is applied as follows:</p><p>finrichment is returned as f\_</p><p>plus the Kubernetes key and the node/pod label is returned as nl\_\<key>/pl\_\<key></p> | <p>“1233442423423”</p><p>“finrichment\_usage\_type” -> “f\_usage\_type”</p><p>Use <a href="https://docs.finout.io/en/articles/85572-finout-query-language-api#h_c9f332bbf2">Finout’s Query Language API</a> to get a list of the available keys.</p> |

Note: "displayName" is retrieved in the GET API call. This parameter should not be sent in the POST/PUT API calls.

### Supported Operators <a href="#h_d40292383d" id="h_d40292383d"></a>

The following operators can be used in the rule definitions to specify filtering conditions:

* oneOf: Matches the resource value if it is equal to any of the specified values.
* notOneOf: Matches the resource value if it is not equal to any of the specified values.
* is: Matches the resource value if it is exactly equal to the specified value.
* isNot: Matches the resource value if it is not equal to the specified value.
* contains: Matches the resource value if it contains the specified substring.
* notContains: Matches the resource value if it does not contain the specified substring.
* exists: Matches the resource value if it exists (not null or empty).
* notExists: Matches the resource value if it does not exist (null or empty).

### Example rule configuration <a href="#h_fa6df223bc" id="h_fa6df223bc"></a>

```json
{
  "requestId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "accountId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "name": "Test",
  "rules": [
    {
      "to": "Finout",
      "filters": {
        "AND": [
          {
            "costCenter": "AWS",
            "key": "aws_account_name",
            "displayName": "Account Name",
            "operator": "oneOf",
            "value": ["Finout"]
          },
          {
            "costCenter": "AWS",
            "key": "f_operation",
            "displayName": "API Operation",
            "operator": "oneOf",
            "value": ["AAAA"]
          },
          {
            "costCenter": "Virtual Tags",
            "key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "displayName": "Cost per Customer",
            "operator": "oneOf",
            "value": ["Abra"]
          }
        ]
      }
    },
    {
      "to": "Finout-Subaccount",
      "filters": {
        "costCenter": "AWS",
        "key": "aws_account_name",
        "displayName": "Account Name",
        "operator": "oneOf",
        "value": ["Finout-Subaccount"]
      }
    },
    {
      "to": "AWS",
      "filters": {
        "costCenter": "Global",
        "key": "cost_center_type",
        "displayName": "Cost Center",
        "operator": "oneOf",
        "value": ["AWS"]
      }
    }
  ],
  "category": "Project",
  "createdBy": "User",
  "updatedBy": "User",
  "createdAt": "Wed Mar 13 2024 15:40:46 GMT+0000 (Greenwich Mean Time)",
  "updatedAt": "Thu Mar 21 2024 10:49:17 GMT+0000 (Greenwich Mean Time)",
  "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "defaultValue": "Untagged"
}

```

In the example above, the rule engine is configured with two rules. The first rule filters resources with costCenter equal to "virtualTag" and type equal to "virtual\_tag" using the oneOf operator, matching the values "Aged", "AllArid", "BidBare", "Calm", or "Coal". The matching resources are then directed to the "Application" destination.

The second rule filters resources with costCenter equal to "virtualTag" and type equal to "virtual\_tag" using the contains operator, matching the value "Jet". The matching resources are directed to the "Backend" destination.

### Example rules and filter conditions <a href="#h_0e1fb12477" id="h_0e1fb12477"></a>

```json
{
  "requestId": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "accountId": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "name": "exampleName",
  "rules": [
    {
      "to": "Tag1",
      "filters": {
        "AND": [
          {
            "OR": [
              {
                "costCenter": "Center1",
                "key": "service_key",
                "displayName": "Service Name",
                "operator": "oneOf",
                "value": [
                  "ServiceA",
                  "ServiceB",
                  "ServiceC"
                ]
              },
              {
                "costCenter": "Center1",
                "key": "account_name_key",
                "displayName": "Account Name",
                "operator": "oneOf",
                "value": [
                  "AccountX",
                  "AccountY"
                ]
              }
            ]
          },
          {
            "costCenter": "Center1",
            "key": "service_key",
            "displayName": "Service Name",
            "operator": "oneOf",
            "value": [
              "ServiceA",
              "ServiceB"
            ]
          }
        ]
      }
    },
    {
      "to": "Tag2",
      "filters": {
        "costCenter": "Center2",
        "key": "account_name_key",
        "displayName": "Account Name",
        "operator": "oneOf",
        "value": [
          "AccountZ",
          "AccountW"
        ]
      }
    }
  ],
  "createdBy": "CreatorName",
  "updatedBy": "UpdaterName",
  "createdAt": "Date and Time",
  "updatedAt": "Date and Time",
  "id": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "defaultValue": "DefaultTag"
}
```

In the provided example, the third rule illustrates complex conditional logic using both "AND" and "OR" operators. This rule's filter conditions demonstrate the logic: "(condition 1 AND condition 2) OR (condition 1 AND condition 3)". This showcases how multiple conditions can be intricately grouped within "AND" or "OR" relationships, allowing for the creation of sophisticated filtering logic for virtual tags. This example serves to show the versatility and depth of the filtering system in handling diverse and complex tagging scenarios.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.finout.io/api/finout-api/filter-object-definition-v1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
