Create custom metadata field

Add custom metadata field

POST https://api.imagekit.io/v1/customMetadataFields

Headers

NameTypeDescription

Authorization*

string

base64 encoding of your_private_api_key:

Note the colon in the end.

Request Body

NameTypeDescription

name*

string

Name of the metadata field, unique across all (deleted or not deleted) custom metadata fields

label*

string

Label of the metadata field, unique across all non deleted custom metadata fields

schema*

object

An object that describes the rules for the custom metadata key.

{
    "id": "598821f949c0a938d57563dd",
    "name": "price",
    "label": "price",
    "schema": {
        "type": "Number",
        "minValue": 1000,
        "maxValue": 3000
    }
}

Allowed values in the schema object

Parameter nameTypeRequiredDescriptions

type

enum

Yes

Type of the field Allowed values - Text, Textarea, Number, Date, Boolean, SingleSelect, MultiSelect

Date value should be an ISO8601 string

selectOptions

An array consisting values of type string, number or boolean

Only if type is SingleSelect or MultiSelect

An array of options to select from. Example - ["small", "medium", "large", 30, 40, true]

defaultValue

string, number or array

Only if isValueRequired is true

The default value for the field

type constraints :

Should be of the same type as that provided in thetype enum.

For SingleSelect, should be one of the values provided in selectOptions

For MultiSelect, should be an array containing only values provided in selectOptions

For Date or Number, should be >= minValue (if provided) and <= maxValue (if provided)

For Text or Textarea, should be >= minLength (if provided) and <= maxLength (if provided)``

isValueRequired

boolean

No

Sets field as required

minValue

string or number

No

Minimum value of the field

Allowed only if type is Date or Number

maxValue

string or number

No

Maximum value of the field

Allowed only if type is Date or Number

minLength

number

No

Minimum length of string

Allowed only if type is Text or Textarea

maxLength

number

No

Maximum length of string

Allowed only if type is Text or Textarea

Examples

Here is the example request to understand the API usage.

# The unique id of the created custom metadata schema is returned with this api along with key name and schema object.
curl -X POST "https://api.imagekit.io/v1/customMetadataFields" \
-H 'Content-Type: application/json' \
-u your_private_key: -d'
{
    "name": "price",
    "label": "price",
    "schema": {
        "type": "Number",
        "minValue": 1000,
        "maxValue": 3000
    }
}
'

Last updated