If you'd like to add or update metadata for assets that are already uploaded to your Media Library, you can do so using the Admin API Update Method. This allows you to modify metadata for existing assets in your account.
To Add Metadata Fields:
You can add new metadata fields by using the following method. Here's an example that adds a "Colors" metadata field with multiple options:
cloudinary.v2.api.add_metadata_field({
"external_id": "color_id",
"label": "Colors",
"type": "set" ,
"mandatory": "true",
"default_value": ["color1","color2"],
"datasource": {
"values": [
{"external_id": "color1", "value": "red"},
{"external_id": "color2", "value": "green"},
{"external_id": "color3", "value": "blue"},
{"external_id": "color4", "value": "yellow"}
]
}
}).then(result=>console.log(result));
To Update an Existing Metadata Field:
If you need to update properties of an existing metadata field (such as its label or mandatory status), you can do so by referencing the field's external_id
:
cloudinary.v2.api.update_metadata_field('color_id', {
"label": "Color Group 1",
"mandatory": true })
.then(result=>console.log(result));
For further details on how to update the metadata of an existing asset, refer to Cloudinary’s documentation:
https://cloudinary.com/documentation/admin_api#update_details_of_an_existing_resource
Comments
0 comments
Please sign in to leave a comment.