Metadata field values
The value property of the metadata value object is overloaded and can take several different types of data. The metadata schema will define which values are valid in this field. Changing metadata field types in the schema in admin mode will cause validation to change and this must be considered when implementing a solution.
The following code sample shows how some metadata fields are used:
{
"metadata_values": {
"description": {"value": "My page about news sport"},
"keywords": {"value": ["sport", "news"]
}}}
Required fields
Required metadata fields are not enforced by the Asset Management API. This must be considered when implementing solutions.
The non-enforcement caters for a use case where metadata fields need to be updated without enforcing the content governance rules for metadata fields. For example, a product database that automatically populates pricing information into Matrix pages, where marketing text is updated by content editors.
Use default
The Use Default option for metadata fields in the Admin UI allows for assets to inherit a default value from the Metadata Schema. This behaviour happens at rendering time, and the default value is not stored on the asset. This means that in the API, the default values are not returned for an asset, instead, it returns null. To implement a solution that infers default values, you will need to get the default values from the relevant schema and use them when the appropriate field returns null. To set a metadata value to ‘use default’, set the metadata field to null, as shown in Remove metadata values.
Select fields
Select fields, such as the keywords field in the example above, can be configured in a number of ways that will all validate differently, and these differences need to be taken into account when using the fields.
The table below shows what the Asset management API will accept for certain configurations on select fields.
Select field configured to allow | Asset management API will accept |
---|---|
Only one value |
A string or an array with one element |
Multiple values |
An array of values |
Empty values |
An empty array or empty string |
null in these circumstances means that the metadata field is not set, and at rendering time any default value set on the Metadata Schema will be used. |
Date fields
Date fields use timestamps, and will be adjusted based on the timezone of the Matrix instance.
The API will not enforce editing constraints configured in the “Editing Style” section of the Date Field details screen in Matrix Admin. While these constraints are applied to content editors using the UI, they may be bypassed for use cases where this is not suitable for an integration. E.g. an integration creating event pages may populate historical event information from a database, while Date Fields are configured so that content editors can only create dates set in the future.