Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Entry

Hierarchy

  • { fields: T; metadata?: MetadataProps; sys: EntityMetaSysProps }
  • DefaultElements<EntryProps>
  • { archive: any; createTask: any; delete: any; getSnapshot: any; getSnapshots: any; getTask: any; getTasks: any; isArchived: any; isDraft: any; isPublished: any; isUpdated: any; patch: any; publish: any; references: any; unarchive: any; unpublish: any; update: any }
    • Entry

Index

Properties

fields

fields: T

Optional metadata

metadata: MetadataProps

sys

Methods

archive

  • archive(): Promise<Entry>
  • Archives 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.getEntry('<entry_id>'))
    .then((entry) => entry.archive())
    .then((entry) => console.log(`Entry ${entry.sys.id} archived.`))
    .catch(console.error)
    

    Returns Promise<Entry>

    Object returned from the server with updated metadata.

createTask

  • Creates a new task for an entry

    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.getEntry('<entry-id>'))
    .then((entry) => entry.createTask({
      body: 'Something left to do',
      assignedTo: '<user-id>',
      status: 'active'
    }))
    .then((task) => console.log(task))
    .catch(console.error)
    

    Parameters

    Returns Promise<Task>

    Promise for the newly created Task

delete

  • delete(): Promise<any>
  • 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.getEntry('<entry_id>'))
    .then((entry) => entry.delete())
    .then(() => console.log(`Entry deleted.`))
    .catch(console.error)
    

    Returns Promise<any>

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

getSnapshot

  • Gets a snapshot of an entry

    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.getEntry('<entry_id>'))
    .then((entry) => entry.getSnapshot('<snapshot_id>'))
    .then((snapshot) => console.log(snapshot))
    .catch(console.error)
    

    Parameters

    • snapshotId: string

      Id of the snapshot

    Returns Promise<Snapshot<EntryProps<Record<string, any>>>>

getSnapshots

  • Gets all snapshots of an entry

    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.getEntry('<entry_id>'))
    .then((entry) => entry.getSnapshots())
    .then((snapshots) => console.log(snapshots.items))
    .catch(console.error)
    

    Parameters

    • Default value query: {} = {}

    Returns Promise<Collection<Snapshot<EntryProps<Record<string, any>>>, SnapshotProps<EntryProps<Record<string, any>>>>>

getTask

  • getTask(id: string): Promise<Task>
  • Gets a task of an entry

    Parameters

    • id: string

    Returns Promise<Task>

    const contentful = require('contentful-management')

    const client = contentful.createClient({ accessToken: '' })

    client.getSpace('') .then((space) => space.getEnvironment('')) .then((environment) => environment.getEntry('')) .then((entry) => entry.getTask(<task-id>)) .then((task) => console.log(task)) .catch(console.error)

    
    

getTasks

  • Gets all tasks of an entry

    Returns Promise<Collection<Task, TaskProps>>

    const contentful = require('contentful-management')

    const client = contentful.createClient({ accessToken: '' })

    client.getSpace('') .then((space) => space.getEnvironment('')) .then((environment) => environment.getEntry('')) .then((entry) => entry.getTasks()) .then((tasks) => console.log(tasks)) .catch(console.error)

    
    

isArchived

  • isArchived(): boolean
  • Checks if entry is archived. This means it's not exposed to the Delivery/Preview APIs.

    Returns boolean

isDraft

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

    Returns boolean

isPublished

  • isPublished(): boolean
  • Checks if the entry is published. A published entry might have unpublished changes

    Returns boolean

isUpdated

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

    Returns boolean

patch

  • patch(ops: OpPatch[]): Promise<Entry>
  • Sends an JSON patch to the server with any changes made to the object's properties

    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.getEntry('<entry_id>'))
    .then((entry) => entry.patch([
      {
        op: 'replace',
        path: '/fields/title/en-US',
        value: 'New entry title'
      }
    ]))
    .then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
    .catch(console.error)
    

    Parameters

    • ops: OpPatch[]

    Returns Promise<Entry>

    Object returned from the server with updated changes.

publish

  • publish(): Promise<Entry>
  • 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.getEntry('<entry_id>'))
    .then((entry) => entry.publish())
    .then((entry) => console.log(`Entry ${entry.sys.id} published.`))
    .catch(console.error)
    

    Returns Promise<Entry>

    Object returned from the server with updated metadata.

references

toPlainObject

unarchive

  • unarchive(): Promise<Entry>
  • Unarchives 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.getEntry('<entry_id>'))
    .then((entry) => entry.unarchive())
    .then((entry) => console.log(`Entry ${entry.sys.id} unarchived.`))
    .catch(console.error)
    

    Returns Promise<Entry>

    Object returned from the server with updated metadata.

unpublish

  • unpublish(): Promise<Entry>
  • 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.getEntry('<entry_id>'))
    .then((entry) => entry.unpublish())
    .then((entry) => console.log(`Entry ${entry.sys.id} unpublished.`))
    .catch(console.error)
    

    Returns Promise<Entry>

    Object returned from the server with updated metadata.

update

  • update(): Promise<Entry>
  • Sends an update to the server with any changes made to the object's properties

    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.getEntry('<entry_id>'))
    .then((entry) => {
      entry.fields.title['en-US'] = 'New entry title'
      return entry.update()
    })
    .then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
    .catch(console.error)
    

    Returns Promise<Entry>

    Object returned from the server with updated changes.