Metadata API reference
Last updated: Feb-13-2023
Overview
Cloudinary structured metadata allows you to define typed fields for media assets, populate them with values programmatically or via the Media Library, and perform searches on them. You can also add validation rules, set default values, and define fields as mandatory.
A metadata field is a custom, typed field (key) for storing user defined data (value) with a media asset.
This page explains the Metadata methods for creating and managing structured metadata fields, as well as the Metadata field structure and how to structure field validation and list (datasource) values.
Quick example
Add a new mandatory metadata set
(multi-select) field with an external_id of 'color_id', labeled 'Colors', and with 4 available colors: red, green, blue and yellow, where red and green are the default values:
\
or "
, for example, \"text\"
or ""text""
.Metadata methods
The Metadata methods enable you to manage the metadata fields available for your product environment.
Method | Description |
---|---|
GET/metadata_fields
|
Lists all metadata field definitions. |
GET/metadata_fields/:external_id
|
Returns a single metadata field definition by external ID. |
POST/metadata_fields
|
Creates a new metadata field definition. |
POST/metadata_fields/:external_id/datasource_restore
|
Restores entries in a metadata field datasource. |
PUT/metadata_fields/:external_id
|
Updates a metadata field definition by external ID. |
PUT/metadata_fields/:external_id/datasource
|
Updates a metadata field datasource by external ID. |
DELETE/metadata_fields/:external_id
|
Deletes a metadata field by external ID. |
DELETE/metadata_fields/:external_id/datasource
|
Deletes entries in a metadata field datasource for a specified metadata field definition. |
Get metadata fields
Returns a list of all metadata field definitions as an array of JSON objects.
See also: Metadata field structure
Syntax
GET /metadata_fields
Sample response
Get a metadata field by external ID
Returns a single metadata field definition.
See also: Metadata field structure
Syntax
GET /metadata_fields/:external_id
Required parameters
Parameter | Type | Description |
---|---|---|
external_id |
String | The ID of the metadata field (included in the endpoint URL when using the REST API). |
Examples
Return the information for the metadata field with the ID of 'in_stock':
Sample response
Create a metadata field
Creates a new metadata field definition. Expects a single JSON object which defines the field, according to the structure for the required field type.
See also: Metadata field structure
Syntax
POST /metadata_fields
Required parameters
Parameter | Type | Description |
---|---|---|
field |
Object | The metadata field to add. For details see Metadata field structure. |
Examples
Add a new mandatory metadata set
(multi-select) field with an external_id of 'color_id', labeled 'Colors', and with 4 available colors: red, green, blue and yellow, where red and green are the default values:
\
or "
, for example, \"text\"
or ""text""
.Sample response
Restore entries in a metadata field datasource
Restores (unblocks) any previously deleted datasource entries for a specified metadata field definition. Sets the state of the entries to active.
See also: Metadata field structure
Syntax
POST /metadata_fields/:external_id/datasource_restore
Required parameters
Parameter | Type | Description |
---|---|---|
external_id |
String | The ID of the metadata field (included in the endpoint URL when using the REST API). |
external_ids |
String[] | An array of IDs of datasource entries to restore (unblock). |
Examples
Restore (unblock) the datasource entry with external_id 'color1' from the metadata field with external_id 'color_id':
Sample response
Update a metadata field by external ID
Updates a metadata field definition (partially, no need to pass the entire object) passed as JSON data.
See also: Metadata field structure
Syntax
PUT /metadata_fields/:external_id
Required parameters
Parameter | Type | Description |
---|---|---|
external_id |
String | The ID of the metadata field (included in the endpoint URL when using the REST API). |
field |
Object | The metadata field to update. For details see Metadata field structure. |
Examples
Update the metadata field with the ID of 'in_stock':
\
or "
, for example, \"text\"
or ""text""
.Sample response
Update a metadata field datasource
Updates the datasource of a supported field type (currently only enum and set), passed as JSON data. The update is partial: datasource entries with an existing external_id will be updated and entries with new external_id's (or without external_id's) will be appended.
See also: Metadata field structure
Syntax
PUT /metadata_fields/:external_id/datasource
Required parameters
Parameter | Type | Description |
---|---|---|
external_id |
String | The ID of the metadata field (included in the endpoint URL when using the REST API). |
entries |
Object | The datasource enties to update. For details see Datasource values. |
Examples
Update the datasource for the metadata field with the ID of ''color_id':
\
or "
, for example, \"text\"
or ""text""
.Sample response
Delete a metadata field by external ID
Deletes a metadata field definition. The field should no longer be considered a valid candidate for all other endpoints (it will not show up in the list of fields, etc).
external_id
s can be reused after fields are deleted, but if the fields had many assignments, the process can take a few minutes and the external_id
will be reserved until the asynchronous deletion is complete.See also: Metadata field structure
Syntax
DELETE /metadata_fields/:external_id
Required parameters
Parameter | Type | Description |
---|---|---|
external_id |
String | The ID of the metadata field (included in the endpoint URL when using the REST API). |
Examples
Delete the metadata field with the ID of 'in_stock':
Sample response
Delete entries in a metadata field datasource
Deletes (blocks) the datasource entries for a specified metadata field definition. Sets the state of the entries to inactive
. This is a soft delete, so the entries still exist under the hood but are marked as having an inactive state
. The entries can be activated again with the restore datasource entries method.
state
property set to inactive
. See also: Metadata field structure
Syntax
DELETE /metadata_fields/:external_id/datasource
Required parameters
Parameter | Type | Description |
---|---|---|
external_id |
String | The ID of the metadata field (included in the endpoint URL when using the REST API). |
external_ids |
String[] | An array of IDs of datasource entries to delete. |
Examples
Delete (block) the datasource entry with external_id 'color4' from the metadata field with external_id 'color_id':
Sample response
Metadata field structure
Parameter | Required | Description |
---|---|---|
external_id |
No | A unique immutable identification string for the metadata field. Default: auto-generated by Cloudinary (although it's recommended to specify a descriptive name). Max character length: 255. |
type |
Yes | The type of value that can be assigned to the metadata field, possible types are limited to: * string - a single string value* integer - a single integer value* date - a custom date in the following format: {yyyy-mm-dd}* enum - a single value referenced by an external_id from a given list, predefined with the datasource parameter* set - multiple values referenced by external_id s from a given list, predefined with the datasource parameter |
label |
Yes | The label of the metadata field for display purposes. |
mandatory |
No | Whether a value must be given for this field, either when an asset is first uploaded, or when it is updated. Default: false
|
restrictions |
No | Any restrictions to apply. Currently can set the readonly_ui boolean parameter to mark this metadata field as read only in the UI (only relevant if mandatory is false). Default: {"readonly_ui": false}
|
default_value |
Yes (if mandatory is true) |
The default value for the field (a set can have multiple default values defined by an array). Default: null
|
validation |
No | Any validation rules to apply when values are entered (or updated) for this field. See Validating data for more details. Default: null
|
datasource |
Yes (for the enum and set type ) |
The predefined list of values, referenced by external_id s, available for this field. See Datasource values for more details. |
Validating data
The validation
parameter defines a validation object with the logic to apply when a value is entered for the field, via the metadata, upload, explicit or update resource methods, or via the Media Library. The boolean validations also allow for combinations of more than one rule. The following validations are supported:
greater_than validation
Relevant for integer
and date
types:
Property | Type | Description |
---|---|---|
value |
String | The value for validation. |
equals |
Boolean | Whether to check if greater than or equals. Default: false
|
For example:
less_than validation
Relevant for integer
and date
types:
Property | Type | Description |
---|---|---|
value |
String | The value for validation. |
equals |
Boolean | Whether to check if less than or equals. Default: false
|
For example:
strlen validation
Relevant only for string
types:
Property | Type | Description |
---|---|---|
min |
Integer | The minimum string length. Default: 0
|
max |
Integer | The maximum string length. Default: 1024
|
For example:
and validation
Relevant for all field types. Allows you to include more than one validation rule to be evaluated:
Property | Type | Description |
---|---|---|
validation_object |
Object | One of the other validations above: greater_than , less_than or strlen
|
For example:
Datasource values
The datasource
parameter is relevant for fields where the selected values must come from a predefined list of values (enum
or set
type fields). The parameter contains the values
property, which defines the values for the enum
or set
list. Up to 3000 values can be defined for a list.
Each datasource_entry
defines a single possible value for the field:
Property | Type | Description |
---|---|---|
external_id |
String | (optional) A unique immutable identification string for the datasource entry, (required if the value is referenced by the default_value field). Default: auto-generated by Cloudinary |
value |
String | (mandatory) The value for this datasource. |
state |
String | (read only) Only given as part of a response - ignored on requests. It is immutable unless changed via DELETE of a datasource entry. |
For example: