Global Fields
Global Fields
Global Fields define the reusable content structure across different parts of your website or mobile application. To start using Global Fields, you must first create its instance in the stack.
To use Nested Global Fields, pass API Version 3.2 as a parameter when calling global_fields() function. You can specify the API version in one of the following ways:
- Passing options directly:
import contentstack_management client = contentstack_management.Client(authtoken='auth_token') response = client.stack('api_key').global_fields(options={"api_version": "3.2"}).create(data) - Targeting a specific global field by UID with options:
import contentstack_management client = contentstack_management.Client(authtoken='auth_token') response = client.stack('api_key').global_fields("uid", options={"api_version": "3.2"}).fetch()
create
The create method creates a new global field in a particular stack.
| Name | Type | Description |
|---|---|---|
| data (required) | Dict | The request body |
data = {
"global_field": {
"title": "Servlet",
"uid": "servlet",
"schema": [{
"display_name": "Name",
"uid": "name",
"data_type": "text"
}
}
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
response = client.stack('api_key').global_fields().create(data)delete
The delete method deletes an existing global field from a particular stack.
| Name | Type | Description |
|---|---|---|
| global_field_uid (required) | str | UID of the global field |
import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")
response = client.stack('api_key').global_fields('global_field_uid').delete()export
The export method exports the existing global fields from a particular stack.
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
response = client.stack('api_key').global_fields().export().json()fetch
The fetch method retrieves the details of a specific global field from a particular stack.
| Name | Type | Description |
|---|---|---|
| global_field_uid (required) | str | UID of the global field |
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
response = client.stack('api_key').global_fields('global_field_uid').fetch().json()find
The find method retrieves the details of all global fields from a particular stack.
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
response = client.stack("api_key").global_fields('global_field_uid').find().json()imports
The imports method imports the global field into a particular stack.
| Name | Type | Description |
|---|---|---|
| global_field_uid (required) | str | UID of the global field |
| file_path (required) | str | File path of the global field to be imported |
import contentstack_management
client = contentstack_management.Client(authtoken='auth_token')
response = client.stack('api_key').global_fields('global_field_uid').imports().json()update
The update method updates the details of an existing global field.
| Name | Type | Description |
|---|---|---|
| global_field_uid (required) | str | UID of the global field |
| data (required) | Dict | The Request body |
data = {
"global_field": {
"title": "Servlet",
"uid": "servlet",
"schema": [{
"display_name": "Name",
"uid": "name",
"data_type": "text"
}
}
import contentstack_management
client = contentstack_management.Client(authtoken="authtoken")
response = client.stack('api_key').global_fields('global_field_uid').update(data)