Skip to content

Metafields

Metafields are powerful components that can be added to Objects and Object Types. Metafields added to Object Types will be default for all new Objects in the type.

Model

ParameterRequiredTypeDescription
typerequiredEnumtext, textarea, html-textarea, select-dropdown, object, objects, file, date, radio-buttons, check-boxes, repeater, parent, markdown, json, switch, number
titlerequiredStringYour Metafield title
keyrequiredStringUnique identifier for your Metafield
valuevariesVaries by typeMetafield value. Property required to be present (empty string ok) except for repeater and parent (should not be present). See example model below for various value types and requirements.
requiredBoolA value is required
regexStringRestrict the value to match a regular expresssion
regex_messageStringThe message displayed when the value fails the regex
minlengthNumberAdd minlength to text or textarea Metafields
maxlengthNumberAdd maxlength to text or textarea Metafields
optionsRequired for options, radio, checkbox and switchVaries by typeArray of options for select, radio, and checkbox Metafields and string for switch Metafield with possible values true,false and yes,no
childrenArrayArray of nested Metafields
object_typeStringValid Object Type slug. Applies only to object and objects Metafield
repeater_fieldsArrayArray of nested Metafields. Applies only to repeater Metafield

Example Metafields

{
"metafields": [
{
"type": "text",
"title": "Headline",
"key": "headline",
"value": "3030 Palo Alto Blvd.",
"required": true
},
{
"type": "textarea",
"title": "Basic Text",
"key": "basic_text",
"value": "This home is a must see!",
"required": true
},
{
"type": "html-textarea",
"title": "Extended Text",
"key": "extended_text",
"value": "<p>Some <strong>HTML content</strong> for <em>dramatic</em> effect!</p>"
},
{
"type": "markdown",
"title": "Markdown Text",
"key": "markdown_text",
"value": "# Hello World!"
},
{
"type": "select-dropdown",
"title": "State",
"key": "state",
"value": "California",
"options": [
{
"key": "CA",
"value": "California"
},
{
"key": "TX",
"value": "Texas"
}
]
},
{
"type": "object",
"title": "Pages",
"key": "pages",
"object_type": "pages",
"value": "5a4806974fa85fc8a7000002" // Object ID
},
{
"type": "objects",
"title": "Other Listings",
"key": "other_listings",
"object_type": "listings",
"value": "5a4806974fa85fc8a7000007,5a4806974fa85fc8a7000008" // Comma-separated Object IDs
},
{
"type": "file",
"title": "Hero",
"key": "hero",
"value": "media-name-property-in-bucket.jpg" // This is the name of your media. Gets converted to url and imgix_url automatically
},
{
"type": "date",
"title": "Listing Start Date",
"key": "listing_start_date",
"value": "2020-10-15"
},
{
"type": "json",
"title": "JSON Data",
"key": "json_data",
"value": {
"strings": "cheese",
"arrays": ["Bradbury", "Charles", "Ramono", "the last Jedi", "Liotta"],
"objects": {
"bools": true,
"nestable": true
}
}
},
{
"type": "radio-buttons",
"title": "Deposit Required",
"key": "deposit_required",
"value": "The Other",
"options": [
{
"value": "This"
},
{
"value": "That"
},
{
"value": "The Other"
}
]
},
{
"type": "check-boxes",
"title": "Amenities",
"key": "amenities",
"value": ["Pool", "Gym"],
"options": [
{
"value": "Pool"
},
{
"value": "Gym"
},
{
"value": "Landscaping"
}
]
},
{
"type": "switch",
"title": "This is great",
"key": "this_is_great",
"value": true,
"options": "true,false"
},
{
"type": "parent", // ! Value is not allowed for parent Metafield !
"title": "Call Out Section",
"key": "call_out_section",
"children": [
{
"type": "text",
"title": "Headline",
"key": "headline",
"value": "You're Going to Love it Here!"
},
{
"type": "html-textarea",
"title": "Section Content",
"key": "section_content",
"value": "<p>You are going to <strong>love</strong> it in Cosmic Village. The best place to raise a team!</p>"
},
{
"type": "file",
"title": "Hero",
"key": "hero",
"value": "big-beautiful-image.jpg"
}
]
},
{
"type": "repeater", // ! Value is not allowed for repeater Metafield !
"title": "Testimonials",
"key": "testimonials",
// Available repeaters
"repeater_fields": [
{
"title": "Name",
"key": "name",
"value": "",
"type": "text",
"required": false
},
{
"title": "Quote",
"key": "quote",
"value": "",
"type": "text",
"required": false
}
],
// Repeating items and values
"children": [
{
"type": "repeating_item",
"children": [
{
"type": "text",
"title": "Name",
"key": "name",
"value": "Fiona Apple"
},
{
"type": "text",
"title": "Name",
"key": "name",
"value": "Jon Brion"
}
]
}
]
}
]
}

Validation

You can use optional validation parameters to make sure editors using the Web Dashboard enter the correct values.

Reference the Metafield model to learn more.

ParameterRequiredTypeDescription
requiredBoolA value is required
regexStringRestrict the value to match a regular expresssion
regex_messageStringThe message displayed when the value fails the regex
minlengthNumberAdd minlength to text or textarea Metafields
maxlengthNumberAdd maxlength to text or textarea Metafields

Example Metafields with Validations

{
"title": "Users",
"singular": "User",
"slug": "users",
"metafields": [
{
"key": "first_name",
"title": "First Name",
"type": "text",
"value": "",
"required": true,
"minlength": 2
},
{
"key": "last_name",
"title": "Last Name",
"type": "text",
"value": "",
"required": true,
"minlength": 2
},
{
"key": "email",
"title": "Email",
"type": "text",
"value": "",
"regex": "/^([a-z0-9_.-]+)@([da-z.-]+).([a-z.]{2,6})$/",
"regex_message": "You must enter a valid email."
},
{
"key": "avatar",
"title": "Avatar",
"type": "file",
"value": ""
},
{
"key": "tagline",
"title": "Tagline",
"type": "text",
"value": "",
"maxlength": 50
}
]
}

Connect Objects

You can connect Objects to create "one to many" and "many to many" relationships between Objects using Single and Multiple Object Metafields.

Definition

POST $BASE_URL/buckets/${bucket_slug}/objects

Example Request

{
"title": "Blog Post Example",
"type": "blog-posts",
"content": "This is some amazing blog content...",
"metafields": [
{
"title": "Headline",
"key": "headline",
"type": "text",
"value": "What I Learned Today"
},
{
"title": "Author",
"key": "author",
"type": "object",
"object_type": "authors",
"value": "5a4ab6e0cf2289b18a2f7599"
},
{
"title": "Categories",
"key": "categories",
"type": "objects",
"object_type": "categories",
"value": "5a4ab6e0cf2289b18a2f7599,5a49d524c1174db128ca2bce"
}
]
}

Single Objects

For a Single Object Metafield, add the Object ID (id) to the value to connect the Object. The full Object will be returned on the Metadata response in the object property.

Multiple Objects

For Multiple Object type Metafields, you can add the Object IDs as comma-separated values. The full Objects will be returned on the Metadata response in the objects property.

ParameterRequiredTypeDescription
typerequiredEnumobject, objects
titlerequiredStringYour Metafield title
keyrequiredStringUnique identifier for your Metafield
object_typerequiredStringObject Type slug
valueStringFor single Object this is the \id property. For multiple Objects it is comma-separated _ids.