@@ -11,6 +11,12 @@ import { createReadStream } from 'fs'
1111
1212export function GlobalField ( http , data = { } ) {
1313 this . stackHeaders = data . stackHeaders
14+ this . apiVersion = data . api_version || undefined ;
15+
16+ if ( this . apiVersion ) {
17+ http . defaults . headers . api_version = this . apiVersion ;
18+ http . httpClientParams . headers . api_version = this . apiVersion ;
19+ }
1420 this . urlPath = `/global_fields`
1521
1622 if ( data . global_field ) {
@@ -36,6 +42,56 @@ export function GlobalField (http, data = {}) {
3642 */
3743 this . update = update ( http , 'global_field' )
3844
45+ /**
46+ * @description The Update GlobalField call lets you update the name and description of an existing GlobalField.
47+ * @memberof GlobalField
48+ * @func update
49+ * @returns {Promise<GlobalField.GlobalField> } Promise for GlobalField instance
50+ * @example
51+ * import * as contentstack from '@contentstack/management'
52+ * const client = contentstack.client()
53+ * const data = {
54+ * "global_field": {
55+ * "title": "Nested Global Field33",
56+ * "uid": "nested_global_field33",
57+ * "schema": [
58+ * {
59+ * "data_type": "text",
60+ * "display_name": "Single Line Textbox",
61+ * "uid": "single_line"
62+ * },
63+ * {
64+ * "data_type": "global_field",
65+ * "display_name": "Global",
66+ * "uid": "global_field",
67+ * "reference_to": "nested_global_field_123"
68+ * }
69+ * ]
70+ * }
71+ * }
72+ * client.stack({ api_key: 'api_key'}).globalField('global_field_uid').updateNestedGlobalField(data, { headers: { api_version: '3.2' }})
73+ * .then((globalField) => {
74+ console.log(globalField)
75+ * })
76+ */
77+ this . updateNestedGlobalField = async ( config , headers = { } ) => {
78+ const apiVersion = { api_version : '3.2' }
79+ this . stackHeaders = { ...this . stackHeaders , ...apiVersion , ...headers }
80+ try {
81+ const headers = {
82+ headers : { ...cloneDeep ( this . stackHeaders ) }
83+ }
84+ const response = await http . put ( `${ this . urlPath } ` , config , headers )
85+ if ( response . data ) {
86+ return response . data
87+ } else {
88+ throw error ( response )
89+ }
90+ } catch ( err ) {
91+ throw error ( err )
92+ }
93+ }
94+
3995 /**
4096 * @description The Delete GlobalField call is used to delete an existing GlobalField permanently from your Stack.
4197 * @memberof GlobalField
@@ -119,8 +175,9 @@ export function GlobalField (http, data = {}) {
119175 * .then((globalField) => console.log(globalField))
120176 *
121177 */
122- this . import = async function ( data , params = { } ) {
178+ this . import = async function ( data , params = { } , headers = { } ) {
123179 try {
180+ this . stackHeaders = { ...this . stackHeaders , ...headers } ;
124181 const response = await upload ( {
125182 http : http ,
126183 urlPath : `${ this . urlPath } /import` ,
0 commit comments