Bind content using the REST API
Data bind properties between content instances using content type bindings.
You can data bind a content or component instance to another content instance so that mapped properties are automatically linked between them. Before you can bind content instances, you must define a content type binding between the content types.
Content bindings are set through the binding field when creating or updating content versions through the Content API at https://api.cms.optimizely.com/v1/content.
The binding field has the following properties:
- contentTypeBinding – The key of the content type binding definition to use.
- source – The permanent URI of the content instance to bind to, in the format
cms://content/<key>?loc=<locale>.
Bind at the top level
To bind an entire content instance to another content instance, specify the binding field at the top level of the content version.
The following example creates a content version that is bound to another content instance using the binding ABinding:
POST https://api.cms.optimizely.com/v1/content
Content-Type: application/json{
"key": "A42574ACC4FF402A94D807B7D45AD6B1",
"contentType": "StandardPage",
"initialVersion": {
"locale": "en",
"displayName": "A bound page",
"routeSegment": "bound_page",
"binding": {
"contentTypeBinding": "ABinding",
"source": "cms://content/256c585881ad452dbd6df90eafadb137?loc=en"
}
}
}You can also add a binding to an existing content version by updating it:
PATCH https://api.cms.optimizely.com/v1/content/A42574ACC4FF402A94D807B7D45AD6B1/versions/1
Content-Type: application/merge-patch+json{
"binding": {
"contentTypeBinding": "ABinding",
"source": "cms://content/256c585881ad452dbd6df90eafadb137?loc=en"
}
}Bind a component property
If a content type has a property of a component content type, and a content type binding exists for that component type, you can bind the component property on a specific content instance to another content instance.
The following example binds the component property AComponent to a source content instance:
POST https://api.cms.optimizely.com/v1/content
Content-Type: application/json{
"key": "A42574ACC4FF402A94D807B7D45AD6B1",
"contentType": "StandardPage",
"initialVersion": {
"locale": "en",
"displayName": "A bound component property",
"routeSegment": "bound_property",
"properties": {
"AComponent": {
"value": {
"binding": {
"contentTypeBinding": "ABinding",
"source": "cms://content/256c585881ad452dbd6df90eafadb137?loc=en"
}
}
}
}
}
}Bind a component in a content list
If a content type binding exists for a component content type, you can bind instances of that component within content list properties. This is useful when working with areas or lists that contain multiple components.
The following example binds a Teaser component within the content list property AnArea:
POST https://api.cms.optimizely.com/v1/content
Content-Type: application/json{
"key": "A42574ACC4FF402A94D807B7D45AD6B1",
"contentType": "StandardPage",
"initialVersion": {
"locale": "en",
"displayName": "A bound component in a list",
"routeSegment": "bound_list_property",
"properties": {
"AnArea": {
"value": [
{
"contentType": "Teaser",
"binding": {
"contentTypeBinding": "ABinding",
"source": "cms://content/256c585881ad452dbd6df90eafadb137?loc=en"
}
}
]
}
}
}
}Updated 2 days ago
