GlobalField

View as Markdown

GlobalField

A Global field is a reusable field (or group of fields) that you can define once and reuse in any content type within your stack.
A nested global field is a reusable group of sub-fields that you define once and embed within other global fields or content types. This allows for a more structured and scalable way to manage complex content models across your stack

Note Pass api_version 3.2 for nested global fields.

update

The Update GlobalField call lets you update the name and description of an existing GlobalField.

Example 1:

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

client.stack({ api_key: 'api_key'}).globalField('global_field_uid').fetch()
.then((globalField) => {
 globalField.title = 'My New global field'
 globalField.description = 'global field description'
 return globalField.update()
})
.then((globalField) => console.log(globalField))

Example 2:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField('global_field_uid', { api_version: '3.2' }).fetch()
.then((globalField) => {
 globalField.title = 'My New global field'
 globalField.description = 'global field description'
 return globalField.update()
})
.then((globalField) => console.log(globalField))

delete

The Delete GlobalField call is used to delete an existing GlobalField permanently from your Stack.

Example 1:

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

client.stack({ api_key: 'api_key'}).globalField('global_field_uid').delete()
.then((response) => console.log(response.notice))

Example 2:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField('global_field_uid', { api_version: '3.2'}).delete()
.then((response) => console.log(response.notice))

fetch

The fetch GlobalField call fetches GlobalField details.

NameTypeDescription
versionnumber

Version number to fetch specific version of GlobalField.

Example 1:

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

client.stack({ api_key: 'api_key'}).globalField('global_field_uid').fetch()
.then((globalField) => console.log(globalField))

Example 2:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField('global_field_uid', { api_version: '3.2'}).fetch()
.then((globalField) => console.log(globalField))

create

The Create a GlobalField call creates a new globalField in a particular stack of your Contentstack account.

NameTypeDescription
params.global_field (required)object

GlobalField details and schema to create.

Example 1:

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

const global_field = {name: 'My New global field'}

client.stack({ api_key: 'api_key'}).globalField().create({ global_field })
.then((globalField) => console.log(globalField))

Example 2:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const global_field = {name: 'My New global field'}
client.stack({ api_key: 'api_key'}).globalField({ api_version: '3.2'}).create({ global_field })
.then((globalField) => console.log(globalField))

query

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

Example 1:

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

client.stack({ api_key: 'api_key'}).globalField().query({ query: { name: 'Global Field Name' } }).find()
.then((globalField) => console.log(globalField))

Example 2:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField({ api_version: '3.2'}).query({ query: { name: 'Global Field Name' } }).find()
.then((globalField) => console.log(globalField))

import

The Import a global field call imports a global field into a stack.

NameTypeDescription
params.global_field (required)string

File path to import GlobalField

Example 1:

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

const data = {
 global_field: 'path/to/file.json',
}

client.stack({ api_key: 'api_key'}).globalField().import(data)
.then((globalField) => console.log(globalField))

Example 2:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = {
 global_field: 'path/to/file.json',
}
client.stack({ api_key: 'api_key'}).globalField({ api_version: '3.2'}).import(data)
.then((globalField) => console.log(globalField))