Conditional metadata rules API reference
Last updated: Feb-13-2023
Overview
Conditional metadata rules allow you to set up dependencies and hierarchical relationships between structured metadata fields and field options. This allows you to:
- Enable/disable (show/hide) another metadata field based on the value selected for a metadata field.
- Activate options displayed for a particular metadata field based on the value specified in another field.
- Set the default metadata value in a particular field based on the value specified in another field.
Some popular use cases for conditional metadata include:
- High-level file type selection, for example: setting metadata fields on different types of content such as image, video and document.
- Support segmenting into categories, for example: product imagery vs lifestyle photography.
- Document asset usage rights, for example: stock imagery.
- Support large organizations with multiple metadata schemas.
For example, one of the metadata fields can include various category values for photos on a company intranet site, such as 'Employee', 'Conference', and 'Culture'. You could set up rules based on these values as follows:
- Selecting 'Employee' in the Category metadata field enables (displays) the Team metadata field with values such as 'R&D', 'Product' or 'HR'.
- Selecting 'R&D' for the Team metadata field enables the Role metadata field with values such as 'QA', 'Devops' or 'Backend'.
- Selecting 'QA' for the Role metadata field enables the Name metadata field with the members of the QA team: 'John Smith' or 'Jane Kelly'. If Devops had been selected for the Role metadata field, then the Name field would be enabled with members of the Devops team: 'Paul Green' or 'Mary Rose'.
Metadata rules endpoint
The Metadata rules API endpoint is accessed using HTTPS. By default, the API endpoint uses the following format:
https://api.cloudinary.com/v1_1/:cloud_name/metadata_rules
For example, to list all Metadata rules in the 'demo' product environment:
The API uses Basic Authentication over secure HTTP. Your Cloudinary API Key and API Secret (which can be found on the Dashboard page of your Cloudinary console) are used for the authentication.
You can experiment with returning a list of the metadata rules in your own Cloudinary product environment by replacing the API_KEY
, API_SECRET
, and CLOUD_NAME
in the cURL command below:
For most actions, request parameters are passed as JSON objects. The response is in a JSON snippet and includes information about the action that was performed.
Metadata rules methods
The Metadata rules methods enable you to manage the metadata rules available for your product environment.
Method | Description |
---|---|
GET/metadata_rules
|
Returns an index of all metadata rules. |
POST/metadata_rules
|
Creates a new metadata rule definition. |
PUT/metadata_rules/:external_id
|
Updates an existing metadata rule definition. |
DELETE/metadata_rules/:external_id
|
Deletes a metadata rule by external ID. |
Get metadata rules
Returns an index of all metadata rules (active and inactive) as an array of JSON objects. The rules are sorted by the dependent metadata field id, and then by their internal order (currently the order of insertion).
Syntax
GET /metadata_rules
Example
Sample response
Create a metadata rule
Creates a new metadata rule definition. Expects a JSON object which defines the rule.
Syntax
POST /metadata_rules
Required parameters
Parameter | Type | Description |
---|---|---|
metadata_field_id | String | The external_id of the metadata field that this rule applies to. |
condition | Object | The condition to evaluate. For details see Condition structure. |
result | Object | The result to apply in the case that the condition is met. For details see Result structure. |
name | String | The name of the metadata rule. |
Example
When the category
metadata field value is equal to 'employee', enable the team
metadata field and activate all the available values:
Sample response
Update a metadata rule by id
Updates an existing metadata rule definition. Expects a JSON object which defines the updated rule.
Syntax
PUT /metadata_rules/:external_id
Required parameters
Parameter | Type | Description |
---|---|---|
external_id | String | The ID of the metadata rule (included in the endpoint URL when using the REST API). |
Optional parameters
Parameter | Type | Description |
---|---|---|
metadata_field_id | String | The external_id of the metadata field that this rule applies to. |
condition | Object | The condition to evaluate. For details see Condition structure. |
result | Object | The result to apply in the case that the condition is met. For details see Result structure. |
name | String | The name of the metadata rule. |
state | String | The current status of the rule, useful for inactivating a rule without deleting it. Possible values: active or inactive
|
Example
When the category
metadata field value is equal to 'employee', enable the team
metadata field and activate all the available values:
Sample response
Delete a metadata rule by id
Deletes a metadata rule definition. The rule should no longer be considered a valid candidate for all other endpoints (it will not show up in the list of rules, etc).
Syntax
DELETE /metadata_rules/:external_id
Required parameters
Parameter | Type | Description |
---|---|---|
external_id | String | The ID of the metadata rule (included in the endpoint URL when using the REST API). |
Example
Delete the metadata rule with an external_id of 'eae809b91168cf3877743713a9dd4b9428bb6f9c37385f6a4897f227b4b86d14':
Sample response
Metadata rule structure
Each metadata rule connects a specified metadata field with a condition to evaluate on a metadata payload (based on other fields' values), and then with a result to apply to the specified metadata field in the case that the condition is met.
Metadata rule = Metadata field + condition + result
Condition structure
The condition that must be met in order to activate the result. Each of the conditions must include the metadata_field_id
(external_id of a metadata field) to evaluate, and the specific criteria to evaluate.
Syntax
Parameters
Property | Type | Description |
---|---|---|
metadata_field_id | String | Required. The external_id of the metadata field to evaluate. |
populated | Boolean | Whether the metadata field is currently populated. |
includes | array of Strings | For multi-select (set) fields - an array of datasource external_ids specifying the current values of the metadata field. |
equals | String | The current value of the metadata field. |
You can set multiple conditions by defining them as and
conditions that must all be met for the result to be applied, or as or
conditions where it is enough that one of the conditions is met.
and
or or
expression by including it as another condition.Examples
Result structure
The result options are applied to the metadata field when the condition is met.
Syntax
Parameters
One or more of the following actions can be applied:
Action | Type | Description |
---|---|---|
enable | Boolean | Whether to enable the metadata field. You can set a metadata field to be disabled by default by updating the metadata field and setting the default_disabled parameter to TRUE. See the note below. |
activate_values | Object | The values that will be available for an 'enum' or 'set' metadata field. Optionally, can use a string value of "all" to activate all the possible values. |
apply_value | Object | The value to apply to the metadata field. |
set_mandatory | Boolean | Whether to set the metadata field as mandatory. |
enable: true
action, a field should first be set to disabled by default. This is done by using the update metadata field method and setting the default_disabled
parameter to TRUE. Note that this parameter is not documented in the update method, and should only be used together with a conditional metadata rule that can enable the field when a condition is met.For example, to set a metadata field with the external_id 'category_id' to disabled by default:
activate_values
The activate_values
action can be set to either activate all the values available ("all"
) or you can specify an object detailing the list of available external_ids
as an array of datasource values by their external_ids, and the mode
to either 'override' the existing values or to 'append' them to the current values.
apply_value
The apply_value
action is used to apply a specified value for the metadata field. For multi-select (set) fields you can apply multiple values by giving an array of datasource external_ids, and the mode
to either apply them as the 'default' values or to 'append' them to the currently selected values.