Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ContentType

Hierarchy

  • { description: string; displayField: string; fields: ContentFields[]; name: string; sys: BasicMetaSysProps & { environment: SysLink; firstPublishedAt?: undefined | string; publishedCounter?: undefined | number; publishedVersion?: undefined | number; space: SysLink } }
  • DefaultElements<ContentTypeProps>
  • { delete: any; getEditorInterface: any; getSnapshot: any; getSnapshots: any; isDraft: any; isPublished: any; isUpdated: any; omitAndDeleteField: any; publish: any; unpublish: any; update: any }
    • ContentType

Index

Properties

description

description: string

displayField

displayField: string

Field used as the main display field for Entries

fields

fields: ContentFields[]

All the fields contained in this Content Type

name

name: string

sys

sys: BasicMetaSysProps & { environment: SysLink; firstPublishedAt?: undefined | string; publishedCounter?: undefined | number; publishedVersion?: undefined | number; space: SysLink }

Methods

delete

  • delete(): Promise<void>
  • Deletes this object on the server.

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.getContentType('<contentType_id>'))
    .then((contentType) => contentType.delete())
    .then(() => console.log('contentType deleted'))
    .catch(console.error)
    

    Returns Promise<void>

    Promise for the deletion. It contains no data, but the Promise error case should be handled.

getEditorInterface

  • Gets the editor interface for the object
    Important note: The editor interface only represent a published contentType.
    To get the most recent representation of the contentType make sure to publish it first

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.getContentType('<contentType_id>'))
    .then((contentType) => contentType.getEditorInterface())
    .then((editorInterface) => console.log(editorInterface.contorls))
    .catch(console.error)
    

    Returns Promise<EditorInterface>

    Object returned from the server with the current editor interface.

getSnapshot

  • Gets a snapshot of a contentType

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.getContentType('<contentType_id>'))
    .then((entry) => entry.getSnapshot('<snapshot-id>'))
    .then((snapshot) => console.log(snapshot))
    .catch(console.error)
    

    Parameters

    • snapshotId: string

      Id of the snapshot

    Returns Promise<SnapshotProps<ContentTypeProps>>

getSnapshots

  • Gets all snapshots of a contentType

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.getContentType('<contentType_id>'))
    .then((entry) => entry.getSnapshots())
    .then((snapshots) => console.log(snapshots.items))
    .catch(console.error)
    

    Returns Promise<Collection<Snapshot<ContentTypeProps>, SnapshotProps<ContentTypeProps>>>

isDraft

  • isDraft(): boolean
  • Checks if the contentType is in draft mode. This means it is not published.

    Returns boolean

isPublished

  • isPublished(): boolean
  • Checks if the contentType is published. A published contentType might have unpublished changes (@see {ContentType.isUpdated})

    Returns boolean

isUpdated

  • isUpdated(): boolean
  • Checks if the contentType is updated. This means the contentType was previously published but has unpublished changes.

    Returns boolean

omitAndDeleteField

  • Omits and deletes a field if it exists on the contentType. This is a convenience method which does both operations at once and potentially less safe than the standard way. See note about deleting fields on the Update method.

    Parameters

    • id: string

    Returns Promise<ContentType>

    Object returned from the server with updated metadata.

publish

  • Publishes the object

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.getContentType('<contentType_id>'))
    .then((contentType) => contentType.publish())
    .then((contentType) => console.log(`${contentType.sys.id} is published`))
    .catch(console.error)
    

    Returns Promise<ContentType>

    Object returned from the server with updated metadata.

toPlainObject

unpublish

  • Unpublishes the object

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.getContentType('<contentType_id>'))
    .then((contentType) => contentType.unpublish())
    .then((contentType) => console.log(`${contentType.sys.id} is unpublished`))
    .catch(console.error)
    

    Returns Promise<ContentType>

    Object returned from the server with updated metadata.

update

  • Sends an update to the server with any changes made to the object's properties.
    Important note about deleting fields: The standard way to delete a field is with two updates: first omit the property from your responses (set the field attribute "omitted" to true), and then delete it by setting the attribute "deleted" to true. See the "Deleting fields" section in the API reference for more reasoning. Alternatively, you may use the convenience method omitAndDeleteField to do both steps at once.

    example
    const contentful = require('contentful-management')
    
    const client = contentful.createClient({
      accessToken: '<content_management_api_key>'
    })
    
    client.getSpace('<space_id>')
    .then((space) => space.getEnvironment('<environment_id>'))
    .then((environment) => environment.getContentType('<contentType_id>'))
    .then((contentType) => {
     contentType.name = 'New name'
     return contentType.update()
    })
    .then(contentType => console.log(contentType))
    .catch(console.error)
    

    Returns Promise<ContentType>

    Object returned from the server with updated changes.