ContentType
ContentType
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.
update
The Update ContentType call lets you update the name and description of an existing ContentType. You can also update the JSON schema of a content type, including fields and different features associated with the content type.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').fetch()
.then((contentType) => {
contentType.title = 'My New Content Type'
contentType.description = 'Content Type description'
return contentType.update()
})
.then((contentType) => console.log(contentType))delete
The Delete ContentType call is used to delete an existing ContentType permanently from your Stack.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').delete()
.then((response) => console.log(response.notice))fetch
The fetch ContentType call fetches ContentType details.
| Name | Type | Description |
|---|---|---|
| version | number | Version number to fetch specific version of ContentType. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').fetch()
.then((contentType) => console.log(contentType))entry
Entry is the actual piece of content created using one of the defined content types.
| Name | Type | Description |
|---|---|---|
| uid | string | Entry uid to perform operation on |
| api_version | string | Pass "3.2" to enable enhanced logic for the publish operation only. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry()
//OR
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('entry_uid')generateUid
Generate uid from the title of content type
| Name | Type | Description |
|---|---|---|
| title (required) | string | Title for which ContentType uid needs to be generated. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType().generateUid('name')create
| Name | Type | Description |
|---|---|---|
| params.content_type (required) | object | ContentType details and schema to create. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const content_type = {name: 'My New contentType'}
client.stack({ api_key: 'api_key'}).contentType().create({ content_type })
.then((contentType) => console.log(contentType))query
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType().query({ query: { name: 'Content Type Name' } }).find()
.then((contentTypes) => console.log(contentTypes))import
| Name | Type | Description |
|---|---|---|
| params.content_type (required) | string | File path to import content type |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = {
content_type: 'path/to/file.json',
}
client.stack({ api_key: 'api_key'}).contentType().import(data)
.then((contentType) => console.log(contentType))