Entry Variant

View as Markdown

Entry Variant

An entry variant is a version of a base entry for one audience or experiment. It holds only the fields that differ from the base entry and takes every other value from it. The EntryVariant class manages the variants of one entry through the Content Management API (CMA). Use this class to

  • list the variants of an entry
  • create or update a variant with the fields that differ from the base entry
  • read the versions of a variant
  • publish, unpublish and delete a variant

Call the variants method of an Entry object that has a UID to get an object, for example stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').variants('<VARIANT_UID>'). Link the content type to a variant group first.

Instance State

  • Call variants() without a UID to work with the variants of the entry, for example query.
  • Call variants('<VARIANT_UID>') to work with one variant, for example fetch and update.
  • Each form has only its own request methods. fetch is undefined on variants(), and query is undefined on variants('<VARIANT_UID>'), so calling the wrong one throws TypeError.
  • variants takes an array too. One UID in the array works like a string. Several UIDs go into the request path as one comma-separated segment, as in variants(['<VARIANT_UID>', '<VARIANT_UID>']).
  • The second argument of variants is a branch. A non-empty string sends the branch header from this object only, as in variants('<VARIANT_UID>', '<BRANCH>').

Warning variants('') and variants([]) return the collection form, because the SDK treats an empty value as no UID. Check the UID before you build the object.

Class-Level Notes

Objects that the read methods return.

  • fetch resolves to an EntryVariant object that contains the variant under its entry property. That object has only the collection-form methods. To change the variant, call variants('<VARIANT_UID>') again.
  • Each item that query().find() returns is a single-variant object. It contains the variant under its variants property, with fetch, update, publish and the other single-variant methods.
  • update and versions resolve to the response body, not to an EntryVariant object.

Publishing.

  • publish and unpublish send the publish request of the base entry. The variant UID that you passed to variants is not part of that request. List the variants in publishDetails.variants.
  • The SDK adds no api_version header to these two requests. Pass it in options.headers.

Headers.

Rate limiting and retry.

  • This SDK automatically retries on 429 with configurable delay and attempt limits.

Additional Resource For more information on the retry options and their defaults, refer to the Contentstack documentation.

Capability Matrix

CapabilitySupportedNotes / Alternative
Create a variant with its own methodNoupdate sends the same request, which creates the variant when it does not exist
Name a version of a variantNoThe SDK has no method for Set Version Name for Entry Variant
Filter the versions of a variantNoversions sends no query parameters
Call update on the object that fetch returnsNoCall variants('<VARIANT_UID>') again and call update on it

Method Index

Work with the variants of an entry. Available on entry('<ENTRY_UID>').variants().

Method NameReturnsDescription
queryA query for entry variants, sent when you call find(), findOne() or count().Builds a variant query.

Work with one variant. Available on entry('<ENTRY_UID>').variants('<VARIANT_UID>').

Method NameReturnsDescription
fetchThe requested entry variant.Retrieves one variant.
updateThe API response with the saved entry variant.Creates or updates a variant.
deleteThe API response with a notice.Deletes a variant.
versionsThe API response with the versions of the entry variant.Lists the versions of a variant.
publishThe API response with a notice.Publishes variants of the entry.
unpublishThe API response with a notice.Unpublishes variants of the entry.

Set request headers. Available on both forms.

Method NameReturnsDescription
addHeaderThe same entry variant, for chaining.Adds one request header.
addHeaderDictThe same entry variant, for chaining.Adds several request headers.
removeHeaderThe same entry variant, for chaining.Removes one request header.

Class-Level Snippet

The snippet below changes the title of one entry variant and publishes that variant to one environment.

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })
const entry = stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')

try {
  const saved = await entry.variants('<VARIANT_UID>').update({
    entry: { title: 'Summer sale', _variant: { _change_set: ['title'] } }
  })
  console.log(saved.entry._version)

  const response = await entry.variants('<VARIANT_UID>').publish({
    publishDetails: {
      environments: ['<ENVIRONMENT>'],
      locales: ['<LOCALE>'],
      variants: [{ uid: '<VARIANT_UID>', version: saved.entry._version }],
      variant_rules: { publish_latest_base_conditionally: true }
    },
    headers: { api_version: '3.2' }
  })
  console.log(response.notice)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

Methods

Each method of the EntryVariant class has its own section below, with its parameters, validation rules, behavior, and examples.

addHeader

addHeader adds one header to every request that this entry variant object sends.

NameTypeDescription
key (required)string

Header name, for example x-request-id.

Default: Not applicable
value (required)string

Header value to send.

Default: Not applicable

Returns: EntryVariant. The same entry variant, for chaining.

Validation

  • There is no client-side validation. A null or undefined key leaves the headers unchanged, and addHeader returns the same object.
  • An invalid value surfaces as a rejected promise from the request method you call next.

Behavior

  • Client-side only. addHeader sends no request.
  • The first header change on this object copies the headers that it inherited from the stack. The change then applies to this object only, not to the stack or to other objects that the same stack creates.
  • Every request method of this object sends its headers. A key that the object already holds gets the new value.
  • query passes the headers of this object on to the query it returns. Change the headers first, then call it.
  • To send api_version with publish and unpublish, you can also pass it in their options.headers.

Example

Basic usage: tag the requests of one entry variant object

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const variant = stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').variants('<VARIANT_UID>').addHeader('x-request-id', 'docs-123')
// Every request this object sends from now on carries the header
console.log(variant.stackHeaders['x-request-id'])

addHeaderDict

addHeaderDict adds several headers to every request that this entry variant object sends.

NameTypeDescription
headerDict (required)object

Header names and values to add.

Default: Not applicable

Returns: EntryVariant. The same entry variant, for chaining.

Validation

  • There is no client-side validation. A null value, or a value that is not an object, leaves the headers unchanged, and addHeaderDict returns the same object.
  • An invalid value surfaces as a rejected promise from the request method you call next.

Behavior

  • Client-side only. addHeaderDict sends no request.
  • Copies every key of headerDict into the headers of this object. A key that the object already holds gets the new value.
  • The first header change on this object copies the headers that it inherited from the stack. The change then applies to this object only.

Example

Basic usage: send two extra headers from one entry variant object

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const variant = stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').variants('<VARIANT_UID>')
  .addHeaderDict({ 'x-request-id': 'docs-123', api_version: '3.2' })
// publish() and unpublish() on this object send both headers
console.log(variant.stackHeaders)

delete

delete removes the entry variant whose UID you passed to variants('<VARIANT_UID>'). The base entry stays.

NameTypeDescription
paramobject

Query parameters, sent as given.

Default: {}
param.localestring

Locale of the variant to delete.

Default: API default

Returns: Promise<Response>. The API response with a notice.

Warning A successful delete removes the variant and its changed fields, and you cannot undo it. To use the variant again, save its fields again with update.

Validation

  • There is no client-side validation.
  • delete exists only on variants('<VARIANT_UID>') and on the items that query().find() returns. On variants() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends DELETE /v3/content_types/{content_type_uid}/entries/{entry_uid}/variants/{variant_uid} with every key of param as a query parameter, as Delete entry variant describes.
  • Resolves to the response body, which carries notice. When the API answers with an empty body, it resolves to { status, statusText } instead.

Example

Basic usage: delete an entry variant

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .delete()
  console.log(response.notice)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: delete the variant of one locale

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .delete({ locale: '<LOCALE>' })
  console.log(response.notice)
} catch (error) {
  console.error(error.errorMessage)
}

fetch

fetch retrieves the entry variant whose UID you passed to variants('<VARIANT_UID>').

NameTypeDescription
paramobject

Query parameters, sent as given.

Default: {}
param.localestring

Locale of the variant to read.

Default: API default
param.include_workflowboolean

Adds the workflow details of the variant.

Default: API default
param.include_publish_detailsboolean

Adds the publish details of the variant.

Default: API default
param.include_rulesboolean

Adds the publish rules of the variant.

Default: API default

Returns: Promise<EntryVariant>. The requested entry variant.

Validation

  • There is no client-side validation.
  • fetch exists only on variants('<VARIANT_UID>'). On variants() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends GET /v3/content_types/{content_type_uid}/entries/{entry_uid}/variants/{variant_uid} with every key of param as a query parameter, as Get single entry variant describes.
  • Resolves to a new EntryVariant object. The variant fields are under its entry property, for example variant.entry.title and variant.entry._variant.
  • The returned object has only query and the header methods. To update, publish or delete the variant, call variants('<VARIANT_UID>') again.

Example

Basic usage: read one entry variant

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const variant = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .fetch()
  console.log(variant.entry.title, variant.entry._variant._change_set)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: read a variant in one locale with workflow, publish and rule details

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const variant = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .fetch({ locale: '<LOCALE>', include_workflow: true, include_publish_details: true, include_rules: true })
  console.log(variant.entry.locale, variant.entry.publish_details)
} catch (error) {
  console.error(error.errorMessage)
}

publish

publish publishes variants of the entry to the environments and locales you name, at once or at a scheduled time.

NameTypeDescription
options (required)object

Settings for the publish request.

Default: Not applicable
options.publishDetails (required)object

Body under entry, with environments, locales and variants.

Default: Not applicable
options.publishDetails.environments (required)string[]

Names of the environments to publish.

Default: Not applicable
options.publishDetails.localesstring[]

Codes of the locales to publish.

Default: API default
options.publishDetails.variants (required)object[]

Variants to publish, each as { uid, version }.

Default: Not applicable
options.publishDetails.variant_rulesobject

Rules such as publish_latest_base_conditionally.

Default: API default
options.localestring

Locale of the entry, sent as locale in the body.

Default: null (not sent)
options.versionnumber

The SDK sends it as version in the body. The API ignores it for variants.

Default: null (not sent)
options.scheduledAtstring

ISO 8601 date and time, sent as scheduled_at.

Default: null (publish at once)
options.headersobject

Extra headers for this request, for example api_version.

Default: {}
options.paramsobject

Query parameters for this request, such as locale.

Default: {}

Returns: Promise<Response>. The API response with a notice.

Validation

  • There is no client-side validation. publish sends publishDetails as it is.
  • Without options, the returned promise rejects with a TypeError, because the SDK reads the keys of options.
  • publish exists only on variants('<VARIANT_UID>') and on the items that query().find() returns. On variants() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends POST /v3/content_types/{content_type_uid}/entries/{entry_uid}/publish with the body { entry: publishDetails, locale, version, scheduled_at }, as Publish entry variant describes. The SDK leaves out locale, version and scheduled_at when they are null.
  • The request goes to the base entry. The variant UID that you passed to variants is not part of it, so list every variant to publish in publishDetails.variants.
  • The API ignores a base entry version in the body. It uses the latest base entry version, or the one that variant_rules selects.
  • The SDK adds no api_version header. Publish entry variant lists api_version as a required header, so pass it in options.headers.
  • options.headers and options.params apply to this request only.
  • Resolves to the response body, which carries notice.

Example

Basic usage: publish one variant to one environment

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .publish({
      publishDetails: {
        environments: ['<ENVIRONMENT>'],
        locales: ['<LOCALE>'],
        variants: [{ uid: '<VARIANT_UID>', version: 1 }]
      },
      headers: { api_version: '3.2' }
    })
  console.log(response.notice)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: schedule the publish request for one locale

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .publish({
      publishDetails: {
        environments: ['<ENVIRONMENT>'],
        locales: ['<LOCALE>'],
        variants: [{ uid: '<VARIANT_UID>', version: 2 }],
      variant_rules: { publish_latest_base_conditionally: true }
      },
      locale: '<LOCALE>',
      version: 2,
      scheduledAt: '2026-12-01T10:00:00.000Z',
      headers: { api_version: '3.2' },
      params: { locale: '<LOCALE>' }
    })
  console.log(response.notice)
} catch (error) {
  console.error(error.errorMessage)
}

query

query builds a request for the variants of one entry. It sends nothing until you call a method of the returned query.

NameTypeDescription
paramsobject

Query parameters for the request.

Default: {}
params.localestring

Locale of the variants to read.

Default: API default
params.include_workflowboolean

Adds the workflow details of each variant.

Default: API default
params.include_publish_detailsboolean

Adds the publish details of each variant.

Default: API default
params.include_rulesboolean

Adds the publish rules of each variant.

Default: API default
params.skipnumber

Number of variants to skip.

Default: API default
params.limitnumber

Maximum number of variants to return.

Default: API default

Returns: Query. A query for entry variants, sent when you call find(), findOne() or count().

Validation

  • There is no client-side validation.
  • query exists only on entry('<ENTRY_UID>').variants(). On variants('<VARIANT_UID>') it is undefined, and calling it throws TypeError.
  • An invalid value surfaces as a rejected promise from the request method you call next.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Client-side only. query copies the headers of this object and params, and returns a Query object.
  • find and findOne send GET /v3/content_types/{content_type_uid}/entries/{entry_uid}/variants, as Get all entry variants describes. count resolves to the response body.
  • Each item in items is a single-variant EntryVariant object. The variant fields are under its variants property, and the object has fetch, update, delete, versions, publish and unpublish.
  • The SDK builds each item from the _variant._uid key of the variant in the response.

Example

Basic usage: list the variants of an entry

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const result = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants()
    .query()
    .find()
  for (const variant of result.items) {
    console.log(variant.variants_uid, variant.variants.title)
  }
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: read the second page of variants in one locale on a branch

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const result = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants(null, '<BRANCH>')
    .query({
      locale: '<LOCALE>',
      include_workflow: true,
      include_publish_details: true,
      include_rules: true,
      skip: 10,
      limit: 10
    })
    .find()
  for (const variant of result.items) {
    console.log(variant.variants_uid, variant.variants.publish_details)
  }
} catch (error) {
  console.error(error.errorMessage)
}

removeHeader

removeHeader removes one header from the requests that this entry variant object sends.

NameTypeDescription
key (required)string

Name of the header to remove.

Default: Not applicable

Returns: EntryVariant. The same entry variant, for chaining.

Validation

  • There is no client-side validation. A null or undefined key, or a key that the object does not hold, leaves the headers unchanged.
  • An invalid value surfaces as a rejected promise from the request method you call next.

Behavior

  • Client-side only. removeHeader sends no request.
  • Removing a header that the object inherited from the stack first copies the inherited headers, so the stack and other objects keep the header.
  • The SDK adds some headers at request time, for example the authorization header of the client. removeHeader cannot remove those.

Example

Basic usage: send requests from one entry variant object without the branch header

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>', branch_uid: '<BRANCH>' })

const variant = stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').variants('<VARIANT_UID>').removeHeader('branch')
// This object now works with the default branch
console.log(variant.stackHeaders.branch)

unpublish

unpublish unpublishes variants of the entry from the environments and locales you name, at once or at a scheduled time.

NameTypeDescription
options (required)object

Settings for the unpublish request.

Default: Not applicable
options.publishDetails (required)object

Body under entry, with environments, locales and variants.

Default: Not applicable
options.publishDetails.environments (required)string[]

Names of the environments from unpublish.

Default: Not applicable
options.publishDetails.localesstring[]

Codes of the locales from unpublish.

Default: API default
options.publishDetails.variants (required)object[]

Variants to unpublish, each as { uid, version }.

Default: Not applicable
options.publishDetails.variant_rulesobject

Rules for the base entry.

Default: API default
options.localestring

Locale of the entry, sent as locale in the body.

Default: null (not sent)
options.versionnumber

The SDK sends it as version in the body. The API ignores it for variants.

Default: null (not sent)
options.scheduledAtstring

ISO 8601 date and time, sent as scheduled_at.

Default: null (unpublish at once)
options.headersobject

Extra headers for this request, for example api_version.

Default: {}
options.paramsobject

Query parameters for this request, such as locale.

Default: {}

Returns: Promise<Response>. The API response with a notice.

Validation

  • There is no client-side validation. unpublish sends publishDetails as it is.
  • Without options, the returned promise rejects with a TypeError, because the SDK reads the keys of options.
  • unpublish exists only on variants('<VARIANT_UID>') and on the items that query().find() returns. On variants() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends POST /v3/content_types/{content_type_uid}/entries/{entry_uid}/unpublish with the body { entry: publishDetails, locale, version, scheduled_at }, as Unpublish entry variant describes. The SDK leaves out locale, version and scheduled_at when they are null.
  • The request goes to the base entry. The variant UID that you passed to variants is not part of it, so list every variant to unpublish in publishDetails.variants.
  • The API ignores a base entry version in the body. It uses the latest base entry version, or the one that variant_rules selects.
  • The SDK adds no api_version header. Unpublish entry variant lists api_version as a required header, so pass it in options.headers.
  • options.headers and options.params apply to this request only.
  • Resolves to the response body, which carries notice.

Example

Basic usage: unpublish one variant from one environment

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .unpublish({
      publishDetails: {
        environments: ['<ENVIRONMENT>'],
        locales: ['<LOCALE>'],
        variants: [{ uid: '<VARIANT_UID>', version: 1 }]
      },
      headers: { api_version: '3.2' }
    })
  console.log(response.notice)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: schedule the unpublish request for one locale

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .unpublish({
      publishDetails: {
        environments: ['<ENVIRONMENT>'],
        locales: ['<LOCALE>'],
        variants: [{ uid: '<VARIANT_UID>', version: 2 }],
      variant_rules: { publish_latest_base_conditionally: true }
      },
      locale: '<LOCALE>',
      version: 2,
      scheduledAt: '2026-12-01T10:00:00.000Z',
      headers: { api_version: '3.2' },
      params: { locale: '<LOCALE>' }
    })
  console.log(response.notice)
} catch (error) {
  console.error(error.errorMessage)
}

update

update creates an entry variant, or updates it when it exists, with the fields that differ from the base entry.

NameTypeDescription
data (required)object

Request body with the variant fields under entry.

Default: Not applicable
data.entry._variant._change_setstring[]

UIDs of the fields that differ from the base entry.

Default: API default
paramsobject

Query parameters, sent as given.

Default: {}
params.localestring

Locale of the variant to save.

Default: API default

Returns: Promise<Response>. The API response with the saved entry variant.

Validation

  • There is no client-side validation. update sends data as the JSON body as it is.
  • update exists only on variants('<VARIANT_UID>') and on the items that query().find() returns. On variants() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends PUT /v3/content_types/{content_type_uid}/entries/{entry_uid}/variants/{variant_uid} with data as the body. Create entry variant and Update entry variant use this same request.
  • Link the content type to a variant group first, as Create entry variant states.
  • Put only the fields that differ in data.entry. The API detects the changes from the values, and the variant takes every other field from the base entry.
  • Resolves to the response body as the API returns it, with the saved variant under entry. It is not an EntryVariant object.

Example

Basic usage: change the title and URL of a variant

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const data = {
  entry: {
    title: 'Summer sale',
    url: '/summer-sale',
    _variant: { _change_set: ['title', 'url'] }
  }
}

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .update(data)
  console.log(response.entry.title, response.entry._version)
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}

All parameters: save a variant in one locale on a branch

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

const data = {
  entry: {
    title: 'Soldes d\'été',
    _variant: { _change_set: ['title'] }
  }
}

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>', '<BRANCH>')
    .update(data, { locale: '<LOCALE>' })
  console.log(response.entry.locale)
} catch (error) {
  console.error(error.errorMessage)
}

versions

versions lists the versions of the entry variant whose UID you passed to variants('<VARIANT_UID>').

This method takes no parameters.

Returns: Promise<Response>. The API response with the versions of the entry variant.

Validation

  • There is no client-side validation.
  • versions exists only on variants('<VARIANT_UID>') and on the items that query().find() returns. On variants() it is undefined, and calling it throws TypeError.
  • The returned promise rejects with an Error when the API rejects the request. The error carries status, statusText, errorMessage, errorCode and errors from the API response.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends GET /v3/content_types/{content_type_uid}/entries/{entry_uid}/variants/{variant_uid}/versions, as Get Details of All Versions of Entry Variant describes.
  • Resolves to the response body as the API returns it, with the versions under versions. A version carries _version_name only when it has a name.
  • Sends no query parameters, so you cannot pass named, include_count, locale, include_updated_at or include_updated_by. Without locale, the API returns the versions of the master locale.

Example

Basic usage: list the versions of an entry variant

import contentstack from '@contentstack/management'

const client = contentstack.client()
const stack = client.stack({ api_key: '<API_KEY>', management_token: '<MANAGEMENT_TOKEN>' })

try {
  const response = await stack.contentType('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>')
    .variants('<VARIANT_UID>')
    .versions()
  for (const version of response.versions) {
    console.log(version._version, version._version_name)
  }
} catch (error) {
  // The API rejected the request. The error carries status, errorCode, errorMessage and errors.
  console.error(error.status, error.errorCode, error.errorMessage)
}