ContentType

View as Markdown

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.

NameTypeDescription
versionnumber

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.

NameTypeDescription
uidstring

Entry uid to perform operation on

api_versionstring

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

NameTypeDescription
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

The Create a content type call creates a new content type in a particular stack of your Contentstack account.
NameTypeDescription
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

The Query on Content Type will allow to fetch details of all or specific Content Type

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

The Import a content type call imports a content type into a stack.

NameTypeDescription
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))