Create custom metadata field
post
https://api.imagekit.io
/v1/customMetadataFields
Add custom metadata field
Parameter name | Type | Required | Descriptions |
---|---|---|---|
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 the type 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 |
Here is the example request to understand the API usage.
cURL
Node.js
Python
PHP
Java
Ruby
Go
.Net
# 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
}
}
'
var ImageKit = require("imagekit");
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
imagekit.createCustomMetadataField(
{
name: "price",
label: "price",
schema: {
type: "Number",
minValue: 1000,
maxValue: 3000
}
},
function(error, result) {
if(error) console.log(error);
else console.log(result);
}
);
from imagekitio import ImageKit
imagekit = ImageKit(
public_key='your_public_api_key',
private_key='your_private_api_key',
url_endpoint = 'https://ik.imagekit.io/your_imagekit_id/'
)
create_custom_metadata_fields = imagekit.create_custom_metadata_fields(options=CreateCustomMetadataFieldsRequestOptions(name="test",
label="test",
schema=CustomMetadataFieldsSchema(
type=CustomMetaDataTypeEnum.Number,
min_value=100,
max_value=200))
)
print("Create custom metadata field-", create_custom_metadata_fields, end="\n\n")
# Raw Response
print(create_custom_metadata_fields.response_metadata.raw)
# print the id of created custom metadata fields
print(create_custom_metadata_fields.id)
# print the schema's type of created custom metadata fields
print(create_custom_metadata_fiecreate_custom_metadata_fieldslds_number.schema.type)
use ImageKit\ImageKit;
$public_key = "your_public_api_key";
$your_private_key = "your_private_api_key";
$url_end_point = "https://ik.imagekit.io/your_imagekit_id";
$imageKit = new ImageKit(
$public_key,
$your_private_key,
$url_end_point
);
$body = [
"name" => "price",
"label" => "Price",
"schema" => [
"type" => 'Number',
"minValue" => 1000,
"maxValue" => 3000,
],
];
$createCustomMetadataField = $imageKit->createCustomMetadataField($body);
echo("Create Custom Metadata Field : " . json_encode($createCustomMetadataField));
CustomMetaDataFieldSchemaObject customMetaDataFieldSchemaObject = new CustomMetaDataFieldSchemaObject();
customMetaDataFieldSchemaObject.setType("Number");
customMetaDataFieldSchemaObject.setMinValue(1000);
customMetaDataFieldSchemaObject.setMaxValue(3000);
CustomMetaDataFieldCreateRequest customMetaDataFieldCreateRequest = new CustomMetaDataFieldCreateRequest();
customMetaDataFieldCreateRequest.setName("price");
customMetaDataFieldCreateRequest.setLabel("price");
customMetaDataFieldCreateRequest.setSchema(customMetaDataFieldSchemaObject);
ResultCustomMetaDataField resultCustomMetaDataField = ImageKit.getInstance().createCustomMetaDataFields(customMetaDataFieldCreateRequest);
imagekitio = ImageKitIo::Client.new("your_private_key", "your_public_key", "your_url_endpoint")
imagekitio.create_custom_metadata_field(
name: 'price',
label: 'price',
schema: {
type: 'Number',
minValue: 1000,
maxValue: 3000
}
)
resp, err := ik.Metadata.CreateCustomField(ctx, metadata.CreateFieldParam{
Name: "price",
Label: "price",
Schema: metadata.Schema{
Type: "Number",
MinValue: 1000,
MaxValue: 3000,
},
})
var imagekit = new ImageKit({
publicKey : "your_public_api_key",
privateKey : "your_private_api_key",
urlEndpoint : "https://ik.imagekit.io/your_imagekit_id/"
});
CustomMetaDataFieldCreateRequest requestModelDate = new CustomMetaDataFieldCreateRequest
{
name = "price",
label = "price"
};
CustomMetaDataFieldSchemaObject schemaDate = new CustomMetaDataFieldSchemaObject
{
type = "Number",
minValue = 1000,
maxValue = 3000
};
requestModelDate.schema = schemaDate;
ResultCustomMetaDataField resultCustomMetaDataFieldDate = imagekit.CreateCustomMetaDataFields(requestModelDate);
Last modified 6mo ago