Content Types
Content Types
Content Type defines the structure or schema of a page or a section of your web or mobile property. To create content for your application, you are required to first create a content type, and then create entries using the content type.
create
The create method creates a new content type in a particular stack.
| Name | Type | Description |
|---|---|---|
| data (required) | Dict | The request body |
import contentstack_management
data = {
"content_type": {
"title": "test content type",
"uid": "content_type_uid",
"schema": [{
"display_name": "Title",
"uid": "title",
"data_type": "text",
"field_metadata": {
"_default": True
},
"unique": False,
"mandatory": True,
"multiple": False
},
{
"display_name": "URL",
"uid": "url",
"data_type": "text",
"field_metadata": {
"_default": True
},
"unique": False,
"multiple": False
}
],
"options": {
"title": "title",
"publishable": True,
"is_page": True,
"singleton": False,
"sub_title": [
"url"
],
"url_pattern": "/:title",
"url_prefix": "/"
}
}
}
content_type = contentstack_management.Client(authtoken='auth_token').stack(api_key='api_key').content_type()
response = content_type.create(data)delete
The delete method deletes an existing content type in a particular stack
| Name | Type | Description |
|---|---|---|
| content_type_uid (required) | str | UID of the content type |
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
content_type = client.stack(api_key='api_key').content_type('content_type_uid')
response = content_type.delete()entry
The entry method retrieves the details of a particular entry in the content type.
| Name | Type | Description |
|---|---|---|
| entry_uid (required) | str | UID of the entry |
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
content_type = client.stack(api_key='api_key').content_type('content_type_uid')
response = content_type.entry()export
The export method exports a specific content type and its schema.
| Name | Type | Description |
|---|---|---|
| content_type_uid (required) | str | UID of the content type |
import contentstack
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
content_type = client.stack(api_key='api_key').content_type('content_type_uid')
response = content_type.export()fetch
The fetch method retrieves the details of a specific content type.
| Name | Type | Description |
|---|---|---|
| content_type_uid (required) | str | UID of the content type |
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
content_type = client.stack(api_key='api_key').content_type('content_type_uid')
response = content_type.fetch()find
The find method retrieves the details of all content types.
import contentstack import contentstack_management content_type = contentstack_management.Client(authtoken='auth_token').stack(api_key='api_key').content_type() response = content_type.find()
imports
The imports method imports the content type into the stack by uploading a JSON file.
| Name | Type | Description |
|---|---|---|
| content_type_uid (required) | str | UID of the content type |
| file_path (required) | str | File path of the content type to be uploaded |
import contentstack
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
content_type = client.stack(api_key='api_key').content_type('content_type_uid')
response = content_type.imports(file_path)references
The references method retrieves the details of the content types in which a specific content type is referred.
import contentstack
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
content_type = client.stack(api_key='api_key').content_type('content_type_uid')
response = content_type.references()set_field_visibility_rules
The set_field_visibility_rules method lets you add the field visibility rules to an existing content type.
| Name | Type | Description |
|---|---|---|
| content_type_uid (required) | str | UID of the content type |
| Data (required) | Dict | The Request body |
import contentstack
import contentstack_management
data = {
"content_type": {
"title": "updatedContentType",
"uid": "content_type_uid",
"schema": [{
"display_name": "Title",
"uid": "title",
"data_type": "text",
"field_metadata": {
"_default": True
},
"unique": False,
"mandatory": True,
"multiple": False
},
{
"display_name": "URL",
"uid": "url",
"data_type": "text",
"field_metadata": {
"_default": True
},
"unique": False,
"multiple": False
},
{
"display_name": "Single Line Textbox",
"uid": "single_line_textbox",
"data_type": "text",
"field_metadata": {
"_default": True
},
"unique": False,
"multiple": False
},
{
"display_name": "Multi Line Textbox",
"uid": "multi_line_textbox",
"data_type": "text",
"field_metadata": {
"_default": True
},
"unique": False,
"multiple": False
}
],
"field_rules": [{
"conditions": [{
"operand_field": "single_line_textbox",
"operator": "equals",
"value": "abc"
}],
"match_type": "all",
"actions": [{
"action": "show",
"target_field": "multi_line_textbox"
}]
}],
"options": {
"title": "title",
"publishable": True,
"is_page": True,
"singleton": False,
"sub_title": ["url"],
"url_pattern": "/:title",
"url_prefix": "/"
}
}
}
client = contentstack_management.Client(authtoken='auth_token')
content_type = client.stack(api_key='api_key').content_type('content_type_uid')
response = content_type.set_field_visibility_rules(data)update
The update method updates the schema of an existing content type
| Name | Type | Description |
|---|---|---|
| content_type_uid (required) | str | UID of the content type |
| Data (required) | Dict | The Request body |
import contentstack
import contentstack_management
data = {
>>> "content_type": {
>>> "title": "updated content type",
>>> "uid": "content_type_uid",
>>> "schema": [
>>> {}
>>> ],
>>> "options": {
>>> "title": "title",
>>> "sub_title": [
>>> "url"
>>> ],
>>> "url_pattern": "/:title",
>>> "url_prefix": "/"
>>> }
>>> }
>>> }
client = contentstack_management.Client(authtoken='auth_token')
content_type = client.stack(api_key='api_key').content_type("content_type_uid")
response = content_type.update(data)