---
title: "Add a new Matching Criteria to a Resource Definition."
method: POST
path: "/orgs/{orgId}/resources/defs/{defId}/criteria"
tags: ["public", "ResourceDefinition", "MatchingCriteria"]
---

# Add a new Matching Criteria to a Resource Definition.

`POST /orgs/{orgId}/resources/defs/{defId}/criteria`

Matching Criteria are combined with Resource Type to select a specific definition. Matching Criteria can be set for any combination of Application ID, Environment ID, Environment Type, and Resource ID. In the event of multiple matches, the most specific match is chosen.

For example, given 3 sets of matching criteria for the same type:

```
 1. {"env_type":"test"}
 2. {"env_type":"development"}
 3. {"env_type":"test", "app_id":"my-app"}
```

If, a resource of that type was needed in an Application `my-app`, Environment `qa-team` with Type `test` and Resource ID `modules.my-module-externals.my-resource`, there would be two resource definitions matching the criteria: #1 & #3. Definition #3 will be chosen because its matching criteria is the most specific.

## Path parameters

- `orgId` string, required
- `defId` string, required

## Request body

- MatchingCriteriaRuleRequest — MatchingCriteriaRule describes Matching Criteria rules.
  - `app_id` string — (Optional) The ID of the Application that the Resources should belong to.
  - `class` string — (Optional) The class of the Resource in the Deployment Set. Can not be empty, if is not defined, set to `default`.
  - `env_id` string — (Optional) The ID of the Environment that the Resources should belong to. If `env_type` is also set, it must match the Type of the Environment for the Criteria to match.
  - `env_type` string — (Optional) The Type of the Environment that the Resources should belong to. If `env_id` is also set, it must have an Environment Type that matches this parameter for the Criteria to match.
  - `res_id` string — (Optional) The ID of the Resource in the Deployment Set. The ID is normally a `.` separated path to the definition in the set, e.g. `modules.my-module.externals.my-database`.

## Response `200`

The newly added Matching Criteria details.

- MatchingCriteriaResponse — Matching Criteria are a set of rules used to choose which Resource Definition to use to provision a particular Resource Type. Matching criteria are made up in order of specificity with least specific first: - Environment Type (`env_type`) - Application (`app_id`) - Environment (`env_id`) - Resource (`res_id`) When selecting matching criteria, the most specific one is selected. In general, this means of all the Matching Criteria fully matching the context, the Matching Criteria Rule with the most specific element filled is chosen. If there is a tie, the next most specific elements are compared and so on until one is chosen. **NOTE:** Humanitec will reject the registration of matching criteria rules that duplicate rules already present for a Resource Type.
  - `app_id` string — (Optional) The ID of the Application that the Resources should belong to.
  - `class` string, required — (Optional) The class of the Resource in the Deployment Set. Can not be empty, if is not defined, set to `default`.
  - `env_id` string — (Optional) The ID of the Environment that the Resources should belong to. If `env_type` is also set, it must match the Type of the Environment for the Criteria to match.
  - `env_type` string — (Optional) The Type of the Environment that the Resources should belong to. If `env_id` is also set, it must have an Environment Type that matches this parameter for the Criteria to match.
  - `id` string, required — Matching Criteria ID
  - `res_id` string — (Optional) The ID of the Resource in the Deployment Set. The ID is normally a `.` separated path to the definition in the set, e.g. `modules.my-module.externals.my-database`.

## Other responses

- `400` — One or more request parameters is missing or invalid.
- `404` — The Resource Definition is not found.
- `409` — A Matching Criteria already exists.
- `500` — Internal application error.

---

[API](https://skmtc.net/humanitec/apis/humanitec-api.md) · [All operations](https://skmtc.net/humanitec/apis/humanitec-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/humanitec/humanitec-api/revisions/e21ad140ec3c/schema)
