Entry

View as Markdown

Entry

An entry is the actual piece of content created using one of the defined content types. Read more about Entries.

update

The update an entry call updates an entry of a selected content type.

Here's how you can update an entry:

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.fetch()

.then((entry) => {

 entry.title = 'My New Entry'

 entry.description = 'Entry description'

 return entry.update()

})

.then((entry) => console.log(entry))

Here's how you can update an entry in a specific locale:

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.fetch()

.then((entry) => {

 entry.title = 'My New Entry'

 entry.description = 'Entry description'

 return entry.update({ locale: 'en-at' })

})

.then((entry) => console.log(entry))

Here's how you can update an entry with multiple assets:

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.fetch()

.then((entry) => {

 entry.title = 'My New Entry'

 entry.file = entry.file.uid // for single asset pass asset uid to entry asset field value

 entry.multiple_file = ['asset_uid_1', 'asset_uid_2'] // for multiple asset pass array of asset uid to entry asset field values

 return entry.update({ locale: 'en-at' })

})

.then((entry) => console.log(entry))

Here's how you can update an entry with referenced entries:

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.fetch()

.then((entry) => {

 entry.title = 'My New Entry'

 entry.reference = entry.reference.uid // for single reference pass reference uid to entry reference field value

 entry.multiple_reference = ['reference_uid_1', 'reference_uid_2'] // for multiple reference pass array of reference uid to entry reference field values

 entry.multiple_content_type_reference = [{_content_type_uid: 'content_type_uid_1', uid: 'reference_uid_1'},

{_content_type_uid: 'content_type_uid_2', uid: 'reference_uid_2'}] // for multiple reference pass array of reference uid to entry reference field values

 return entry.update({ locale: 'en-at' })

})

.then((entry) => console.log(entry))

delete

The Delete an entry call is used to delete a specific entry from a content type.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.delete()

.then((response) => console.log(response.notice))

fetch

The fetch Entry call fetches Entry details.
NameTypeDescription
params.versionnumber

Enter the version number of the entry that you want to retrieve. However, to retrieve a specific version of an entry, you need to keep the environment parameter blank.

params.localestring

Enter the code of the language of which the entries need to be included. Only the entries published in this locale will be displayed.

params.include_workflow (required)boolean

Enter 'true' to include the workflow details of the entry.

params.include_publish_detailsstring

Enter 'true' to include the publish details of the entry.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.fetch()

.then((entry) => console.log(entry))

publish

The publish call is used to publish a specific version of an entry on the desired environment either immediately or at a later date/time.

NotePass api_version 3.2 to use enhanced logic to publish

NameTypeDescription
params.publishDetails (required)object

Details of entry to be publish.

params.localestring

Enter the code of the locale that the entry belongs to.

params.versionnumber

Entry version to be publish

params.scheduledAtstring

Schedule date for publishing entry.

Example 1
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

const entry = {
 "locales": [
             "en-us"
             ],
  "environments": [
               "development"
              ]
}
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.publish({ publishDetails: entry, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))
Example 2
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const entry = {
 "locales": [
             "en-us"
             ],
  "environments": [

               "development"
              ]
}
client.stack({ api_key: 'api_key'}).contentType('content_type_uid')
.entry(entryUid, { api_version: '3.2' })
.publish({ publishDetails: entry, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})

.then((response) => console.log(response.notice))

unpublish

The unpublish call is used to unpublish a specific version of an entry on the desired environment either immediately or at a later date/time.

NameTypeDescription
params.publishDetails (required)object

Details of entry to be unpublished.

params.localestring

Enter the code of the locale that the entry belongs to.

params.versionnumber

Entry version to be publish

params.scheduledAtstring

Schedule date for publishing entry.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


const entry = {

 "locales": [

             "en-us"

             ],

  "environments": [

               "development"

              ]

}

client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.unpublish({ publishDetails: entry, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})

.then((response) => console.log(response.notice))

publishRequest

This multipurpose request allows you to either send a publish request or accept/reject a received publish request.

NameTypeDescription
params.publishing_rule (required)object

Details for the publish request

localestring

Enter the code of the locale that the entry belongs to.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


const publishing_rule = {

"uid": "uid",

"action": "publish" 

"status": 1,

"notify": false,

"comment": "Please review this."

}

client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.publishRequest({ publishing_rule, locale: 'en-us'})

.then((response) => console.log(response.notice))

setWorkflowStage

The Set Entry Workflow Stage request allows you to either set a particular workflow stage of an entry or update the workflow stage details of an entry.

NameTypeDescription
params.publishing_rule (required)object

Details for the publish request

localestring

Enter the code of the locale that the entry belongs to.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


const workflow_stage = {

   "comment": "Workflow Comment",

   "due_date": "Thu Dec 01 2018",

   "notify": false,

   "uid": "workflow_stage_uid",

   "assigned_to": [{

     "uid": "user_uid",

     "name": "Username",

     "email": "user_email_id"

     }],

   "assigned_by_roles": [{

   "uid": "role_uid",

   "name": "Role name"

 }]

}


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')

.setWorkflowStage({workflow_stage, locale: 'en-us'})

.then((response) => console.log(response.notice));

create

The Create an entry call creates a new entry in a particular stack of your Contentstack account.

NameTypeDescription
params.entry (required)object

Entry details to create.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


const entry  = {

 title: 'Sample Entry',

 url: '/sampleEntry',

 file = asset_uid, /

 multiple_file = ['asset_uid_1', 'asset_uid_2'], 

 reference: reference.uid, 

multiple_reference: ['reference_uid_1', 'reference_uid_2'], 

 multiple_content_type_reference: [{_content_type_uid: 'content_type_uid_1', uid: 'reference_uid_1'},

{_content_type_uid: 'content_type_uid_2', uid: 'reference_uid_2'}] 

}


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry().create({ entry })

.then((entry) => console.log(entry))

query

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

NameTypeDescription
params.localestring

Enter the code of the language of which the entries need to be included. Only the entries published in this locale will be displayed.

params.include_workflowboolean

Enter 'true' to include the workflow details of the entry.

params.include_publish_detailsboolean

Enter 'true' to include the publish details of the entry.

params.queryobject

Queries that you can use to fetch filtered results.

limitnumber

Specifies the maximum number of entries to return.

Default: 100
skipnumber

Specifies the number of entries to skip. Used for pagination.

Default: 100
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry().query({ query: { title: 'entry title' } }).find()
.then((entry) => console.log(entry))

Note Always include the locale filter inside the query object when filtering entries.

  • Correct usage query({ query: { locale: 'en-gb' } })
    Returns only entries that match the specified locale.
  • Incorrect usage query({ locale: 'en-gb' })
    The locale is treated as a query option, not a filter. All entries are returned.

import

The Import an entry call imports an entry into a stack.

NameTypeDescription
params.entry (required)string

File path to import Entry

localestring

Enter the code of the language to import the entry of that particular language.

overwriteboolean

Select 'true' to replace an existing entry with the imported entry file.

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken })


const data = {

 entry: 'path/to/file.json',

}


client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry().import(data)

.then((entry) => console.log(entry))