Variant
Variant
Variants enable content editors to tailor content for personalized messaging. They help address diverse needs by optimizing reuse and reducing duplication.
Create variant
The Create a variant method creates a new variant in a specific variant group in your stack.
| Name | Type | Description |
|---|---|---|
| params.variant (required) | object | Details of the entry variant |
Example:
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const variant = {
"uid": "iphone_color_white", // optional
"name": "White"
}
client.stack({ api_key: 'api_key'})
.variantGroup('variant_group_uid')
.variants().create({ variant })
.then((variant) => console.log(variant))Update variant
The Update variant method updates an entry for the specified variant group and variants.
| Name | Type | Description |
|---|---|---|
| variant_uid (required) | string | Enter the UID of the variant |
| data (required) | object | Details of the entry variant entry |
Example:
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = { name: 'updated name' }
client.stack({ api_key: 'api_key'})
.variantGroup('variant_group_uid')
.variants('variant_uid')
.update(data)
.then((variant) => console.log(variant))Delete variant
The Delete variant method deletes a specific variant from a variant group.
| Name | Type | Description |
|---|---|---|
| variant_uid (required) | string | Enter the UID of the variant |
Example:
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'})
.variantGroup('variant_group_uid')
.variants('variant_uid')
.delete()
.then((response) => console.log(response.notice));Get a single variant
The Get a single variant method allows you to retrieve the details of a specified variant.
| Name | Type | Description |
|---|---|---|
| variant_uid (required) | string | Enter the UID of the variant |
Example:
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'})
.variantGroup('variant_group_uid')
.variants('variant_uid')
.fetch();
.then((variant) => console.log(variant));Create variant
The Create variant method allows you to create an ungrouped variant.
| Name | Type | Description |
|---|---|---|
| data (required) | object | Details of the entry variant |
Example:
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = {
"uid": "iphone_color_white", // optional
"name": "White",
"personalize_metadata": {
"experience_uid": "exp1",
"experience_short_uid": "expShortUid1",
"project_uid": "project_uid1",
"variant_short_uid": "variantShort_uid1"
},
}
client.stack({ api_key: 'api_key'}).variants().create({ data })
.then((variant) => console.log(variant))