Custom metadata fields API
Imagekit.io allows you to define a schema for your metadata keys and the value filled against that key will have to adhere to those rules. You can create, read and update custom metadata rules and update your file with custom metadata value in file update API or file upload API.

Some real-life applications

Custom metadata fields can be used to store any type of data about your images in key-value pairs.
For example, if you store product images in the media library, you can add custom metadata such as product SKU, price, brand, discount, description, etc.
1
{
2
"SKU": "VS882HJ2JD",
3
"price": 599.99,
4
"brand": "H&M",
5
"discount": 30,
6
"description": "Black casual shirt, has a spread collar, a full button placket, long sleeves with roll-up button tabs, a patch pocket and a curved hem."
7
}
Copied!

Custom metadata fields schema

You can create schemas for the above custom metadata fields.
SKU
1
{
2
"name": "SKU",
3
"schema": {
4
"type": "Text"
5
}
6
}
Copied!
This type of schema will allow string values in SKU custom metadata field, like "VS882HJ2JD", "2JD93NMS2G" etc.
Invalid values of other data types like number (e.g.5682342234), boolean (e.g. true) etc. will be rejected with an error.
Price
1
{
2
"name": "price",
3
"schema": {
4
"type": "Number",
5
"minValue": 1000,
6
"maxValue": 3000
7
}
8
}
Copied!
This schema will allow numerical values within the specified range in price field, like 1000, 1299, 2459.59, 3000 etc.
Invalid values of other data types like text (e.g."one thousand three"), boolean (e.g. true), or numbers below range (e.g. 900) and above range (e.g. 3001) etc. will be rejected with an error.
Size
1
{
2
"name": "size",
3
"schema": {
4
"type": "SingleSelect",
5
"selectOptions": ["XS", "S", "M", "L", "XL", "XXL"],
6
"isValueRequired": true,
7
"defaultValue": "M"
8
}
9
}
Copied!
This schema will allow only one of the values listed in selectOptions in size field, i.e. S, L, XXL etc. It is a required field with the default value M that will be applied on all files if none is provided. Invalid values i.e. values that aren't present in selectOptions like XXS, XXXL etc will be rejected with an error.
Description
1
{
2
"name": "description",
3
"schema": {
4
"type": "Textarea",
5
"minLength": 100,
6
"maxLength": 500
7
}
8
}
Copied!
This schema will allow valid text values within the specified length in decription custom metadata field key, e.g.
"Black casual shirt, has a spread collar, a full button placket, long sleeves with roll-up button tabs, a patch pocket, and a curved hem."
Invalid values of other data types like number (e.g.675), boolean (e.g. true), or text input below or above the length requirement (e.g. string with less than 100 characters) will be rejected with an error.
Brand
1
{
2
"name": "brand",
3
"schema": {
4
"type": "Text"
5
}
6
}
Copied!
This type of schema will allow string values like H&M, Nike etc. in brand field.
Invalid values of other data types like number (e.g.8738), boolean (e.g. true) etc. will be rejected with an error.
Discount
1
{
2
"name": "discount",
3
"schema": {
4
"type": "Number",
5
"minValue": 0,
6
"maxValue": 60,
7
"defaultValue": 20
8
}
9
}
Copied!
This schema will allow numerical values within the specified range in discount field e.g. 0, 10, 22.5, 60 etc. If no value is supplied, it will set discount to 20 by default.
Invalid values of other data types like text (e.g."fifty percent"), boolean (e.g. true), or numbers below range (e.g. -40) and above range (e.g. 70) etc. will be rejected with an error. After creating these custom metadata fields using the API, you can add values for these respective keys in your files using update file API or during file upload.

Allowed values for custom metadata field type in schema

Allowed values - Text, Textarea, Number, Date, Boolean, SingleSelect, MultiSelect
Field type
Description
Examples
Text
Accepts string values, meant to be used for short strings.
Nike, Red cashmere sweater
Textarea
Accepts string values, meant to be used for longer strings, like descriptions.
"Black casual shirt, has a spread collar, a full button placket, long sleeves with roll-up button tabs, a patch pocket and a curved hem."
Number
Accepts numerical values including negative numbers and decimals.
100, -10, 0.09, 7000
Date
Accepts ISO8601 string Date values.
2010-11-05T05:06:07
Boolean
Accepts boolean values.
true, false
SingleSelect
Accepts an array of string, number or boolean values
["S", "M", 30, 40, false]
MultiSelect
Accepts an array of string, number or boolean values
["L", "XL", 60, 90, true]
All the possible values of schemaobject can be found here.
Last modified 28d ago