@agility/management-sdk 0.1.37 → 0.1.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,371 +1,396 @@
1
- # Agility CMS & Management API TypeScript SDK
2
-
3
- ## Table of Contents
4
-
5
- - [About the Management API SDK](#about-the-management-api-sdk)
6
- - [Getting Started](#getting-started)
7
- - [Authentication & Setup](./docs/auth.md)
8
- - [API Method Classes](#api-method-classes)
9
- - [Examples](#examples)
10
- - [TypeScript Interfaces](#typescript-interfaces)
11
- - [Available Enums](#available-enums)
12
-
13
- ---
14
-
15
- ## About the Management API SDK
16
-
17
- - Provides a facility to developers to use the new Agility Management API more effectively.
18
- - Provides methods to perform operations on Assets, Batches, Containers, Content, Models, Pages, and Users.
19
- - **Content and Page Creation** - Create individual or multiple content items and pages (which automatically get added to batches).
20
- - **Essential batch workflow operations** - Perform publish, unpublish, approve, decline, and request approval operations on existing batches.
21
- - Ability to generate Content in bulk for a Website.
22
- - **Strongly typed TypeScript interfaces** for all batch operations with comprehensive error handling.
23
-
24
- ## Getting Started
25
-
26
- ### Prerequisites
27
- 1. Clone the repository agility-cms-management-sdk-typescript.
28
- 2. Import the index file to make use of the Options class.
29
- 3. You will need valid Agility CMS credentials to authenticate and obtain an access token.
30
-
31
- ### Authentication
32
- For detailed authentication instructions, including OAuth 2.0 setup, token management, and security best practices, see the **[Authentication & Setup Guide](./docs/auth.md)**.
33
-
34
- ### Making a Request
35
-
36
- #### Simple OAuth Authentication (Recommended)
37
-
38
- 1. First, initiate the authorization flow by making a GET request to the authorization endpoint:
39
- ```javascript
40
- const authUrl = 'https://mgmt.aglty.io/oauth/authorize';
41
-
42
- //if you wish to implement offline access using refresh tokens, use this URL (enables refresh tokens)
43
- //const authUrl = 'https://mgmt.aglty.io/oauth/authorize?scope=offline-access ';
44
-
45
- const params = new URLSearchParams({
46
- response_type: 'code',
47
- redirect_uri: 'YOUR_REDIRECT_URI',
48
- state: 'YOUR_STATE',
49
- scope: 'openid profile email offline_access'
50
- });
51
-
52
- // Redirect the user to the authorization URL
53
- window.location.href = `${authUrl}?${params.toString()}`;
54
- ```
55
-
56
- 2. After successful authentication, you'll receive an authorization code at your redirect URI. Use this code to obtain an access token:
57
- ```javascript
58
- const response = await fetch('https://mgmt.aglty.io/oauth/token', {
59
- method: 'POST',
60
- headers: {
61
- 'Content-Type': 'application/x-www-form-urlencoded'
62
- },
63
- body: new URLSearchParams({
64
- code: 'YOUR_AUTHORIZATION_CODE'
65
- })
66
- });
67
-
68
- const { access_token, refresh_token, expires_in } = await response.json();
69
- ```
70
-
71
- 3. Use the obtained token to initialize the SDK:
72
- ```javascript
73
- import * as mgmtApi from "@agility/management-sdk";
74
-
75
- // Initialize the Options Class with your authentication token
76
- let options = new mgmtApi.Options();
77
- options.token = access_token; // Use the token obtained from authentication
78
-
79
- // Initialize the APIClient Class
80
- let apiClient = new mgmtApi.ApiClient(options);
81
-
82
- let guid = "<<Provide the Guid of the Website>>";
83
- let locale = "<<Provide the locale of the Website>>"; // Example: en-us
84
-
85
- // Now you can make authenticated requests
86
- var contentItem = await apiClient.contentMethods.getContentItem(22, guid, locale);
87
- console.log(JSON.stringify(contentItem));
88
- ```
89
-
90
- 4. When the access token expires, use the refresh token to obtain a new access token:
91
- ```javascript
92
- const response = await fetch('https://mgmt.aglty.io/oauth/refresh', {
93
- method: 'POST',
94
- headers: {
95
- 'Content-Type': 'application/json'
96
- },
97
- body: JSON.stringify({
98
- refresh_token: 'YOUR_REFRESH_TOKEN'
99
- })
100
- });
101
-
102
- const { access_token, refresh_token, expires_in } = await response.json();
103
- ```
104
-
105
-
106
- #### Manual Token Authentication (For CI/CD)
107
- ```typescript
108
- import * as mgmtApi from "@agility/management-sdk";
109
-
110
- // Token-based approach for CI/CD and automated environments
111
- const options = new mgmtApi.Options();
112
- options.token = process.env.AGILITY_API_TOKEN;
113
- const apiClient = new mgmtApi.ApiClient(options);
114
-
115
- const guid = process.env.AGILITY_GUID;
116
- const locale = "en-us";
117
-
118
- const contentItem = await apiClient.contentMethods.getContentItem(22, guid, locale);
119
- console.log('Content retrieved:', contentItem.fields.title);
120
- ```
121
-
122
- > 💡 **Note**: The new OAuth authentication requires `keytar` for secure token storage. See the [Authentication & Setup Guide](./docs/auth.md) for OAuth setup or [CI/CD & Automated Environments](./docs/cicd.md) for token-based authentication.
123
-
124
- ## API Method Classes
125
-
126
- ### File and Media Management
127
- - **[AssetMethods](./docs/asset-methods.md)** - File and media management operations (15 functions)
128
- - [deleteFile](./docs/asset-methods.md#deletefile), [moveFile](./docs/asset-methods.md#movefile), [getMediaList](./docs/asset-methods.md#getmedialist), [getGalleries](./docs/asset-methods.md#getgalleries), [getGalleryById](./docs/asset-methods.md#getgallerybyid), [getGalleryByName](./docs/asset-methods.md#getgallerybyname), [getDefaultContainer](./docs/asset-methods.md#getdefaultcontainer), [saveGallery](./docs/asset-methods.md#savegallery), [deleteGallery](./docs/asset-methods.md#deletegallery), [getAssetByID](./docs/asset-methods.md#getassetbyid), [getAssetByUrl](./docs/asset-methods.md#getassetbyurl), [upload](./docs/asset-methods.md#upload), [createFolder](./docs/asset-methods.md#createfolder), [deleteFolder](./docs/asset-methods.md#deletefolder), [renameFolder](./docs/asset-methods.md#renamefolder)
129
-
130
- ### Workflow Operations
131
- - **[BatchMethods](./docs/batch-methods.md)** - Batch workflow operations (7 functions)
132
- - [getBatch](./docs/batch-methods.md#getbatch), [publishBatch](./docs/batch-methods.md#publishbatch), [unpublishBatch](./docs/batch-methods.md#unpublishbatch), [approveBatch](./docs/batch-methods.md#approvebatch), [declineBatch](./docs/batch-methods.md#declinebatch), [requestApprovalBatch](./docs/batch-methods.md#requestapprovalbatch), [getBatchTypes](./docs/batch-methods.md#getbatchtypes)
133
-
134
- ### Content Management
135
- - **[ContainerMethods](./docs/container-methods.md)** - Container management operations (8 functions)
136
- - [getContainerByID](./docs/container-methods.md#getcontainerbyid), [getContainersByModel](./docs/container-methods.md#getcontainersbymodel), [getContainerByReferenceName](./docs/container-methods.md#getcontainerbyreferencename), [getContainerSecurity](./docs/container-methods.md#getcontainersecurity), [getContainerList](./docs/container-methods.md#getcontainerlist), [getNotificationList](./docs/container-methods.md#getnotificationlist), [saveContainer](./docs/container-methods.md#savecontainer), [deleteContainer](./docs/container-methods.md#deletecontainer)
137
-
138
- - **[ContentMethods](./docs/content-methods.md)** - Content item operations (14 functions)
139
- - [getContentItem](./docs/content-methods.md#getcontentitem), [publishContent](./docs/content-methods.md#publishcontent), [unPublishContent](./docs/content-methods.md#unpublishcontent), [batchWorkflowContent](./docs/content-methods.md#batchworkflowcontent), [contentRequestApproval](./docs/content-methods.md#contentrequestapproval), [approveContent](./docs/content-methods.md#approvecontent), [declineContent](./docs/content-methods.md#declinecontent), [deleteContent](./docs/content-methods.md#deletecontent), [saveContentItem](./docs/content-methods.md#savecontentitem), [saveContentItems](./docs/content-methods.md#savecontentitems), [getContentItems](./docs/content-methods.md#getcontentitems), [getContentList](./docs/content-methods.md#getcontentlist), [getContentHistory](./docs/content-methods.md#getcontenthistory), [getContentComments](./docs/content-methods.md#getcontentcomments)
140
-
141
- - **[ModelMethods](./docs/model-methods.md)** - Content model operations (6 functions)
142
- - [getContentModel](./docs/model-methods.md#getcontentmodel), [getModelByReferenceName](./docs/model-methods.md#getmodelbyreferencename), [getContentModules](./docs/model-methods.md#getcontentmodules), [getPageModules](./docs/model-methods.md#getpagemodules), [saveModel](./docs/model-methods.md#savemodel), [deleteModel](./docs/model-methods.md#deletemodel)
143
-
144
- ### Page Management
145
- - **[PageMethods](./docs/page-methods.md)** - Page management operations (18 functions)
146
- - [getPage](./docs/page-methods.md#getpage), [getPageByPath](./docs/page-methods.md#getpagebypath), [getPageHistory](./docs/page-methods.md#getpagehistory), [getPageComments](./docs/page-methods.md#getpagecomments), [getPageList](./docs/page-methods.md#getpagelist), [getPageListByPageTemplateID](./docs/page-methods.md#getpagelistbypagetemplateid), [getPageListByPage](./docs/page-methods.md#getpagelistbypage), [getPageListByPageAndPageTemplateID](./docs/page-methods.md#getpagelistbypageandpagetemplateid), [getPageTree](./docs/page-methods.md#getpagetree), [getPageTemplateList](./docs/page-methods.md#getpagetemplatelist), [getPageSecurity](./docs/page-methods.md#getpagesecurity), [getPageItemTemplateList](./docs/page-methods.md#getpageitemtemplatelist), [getPageContentZones](./docs/page-methods.md#getpagecontentzones), [savePage](./docs/page-methods.md#savepage), [savePageSecurity](./docs/page-methods.md#savepagesecurity), [movePageItem](./docs/page-methods.md#movepageitem), [deletePage](./docs/page-methods.md#deletepage), [batchWorkflowPages](./docs/page-methods.md#batchworkflowpages)
147
-
148
- ### User Management
149
- - **[InstanceMethods](./docs/instance-methods.md)** - Instance-level operations (1 function)
150
- - [getLocales](./docs/instance-methods.md#getlocales)
151
-
152
- - **[InstanceUserMethods](./docs/instance-user-methods.md)** - Instance user management (3 functions)
153
- - [getUsers](./docs/instance-user-methods.md#getusers), [saveUser](./docs/instance-user-methods.md#saveuser), [deleteUser](./docs/instance-user-methods.md#deleteuser)
154
-
155
- - **[ServerUserMethods](./docs/server-user-methods.md)** - Server user operations (2 functions)
156
- - [me](./docs/server-user-methods.md#me), [you](./docs/server-user-methods.md#you)
157
-
158
- ### Integration
159
- - **[WebhookMethods](./docs/webhook-methods.md)** - Webhook management (4 functions)
160
- - [getWebhook](./docs/webhook-methods.md#getwebhook), [webhookList](./docs/webhook-methods.md#webhooklist), [saveWebhook](./docs/webhook-methods.md#savewebhook), [deleteWebhook](./docs/webhook-methods.md#deletewebhook)
161
-
162
- ### Multi-Instance Operations
163
- - **[Multi-Instance Operations](./docs/multi-instance-operations.md)** - Advanced workflows for managing content across multiple instances and locales
164
- - Configuration-driven content creation across multiple environments
165
- - Parallel processing and batch operations
166
- - Performance optimization and error handling
167
- - Cross-instance synchronization and reporting
168
-
169
- ### CI/CD & Automation
170
- - **[CI/CD & Automated Environments](./docs/cicd.md)** - Token-based authentication for automated environments
171
- - CI/CD pipeline examples (GitHub Actions, GitLab CI, Jenkins)
172
- - Serverless functions (AWS Lambda, Vercel)
173
- - Environment configuration and security best practices
174
- - Token management and rotation
175
-
176
- ## Examples
177
-
178
- ### Understanding Agility CMS Batch Architecture
179
-
180
- Agility CMS uses a simple approach for working with content and batches:
181
-
182
- #### Content/Page Creation (Handled by Respective Controllers)
183
- - **contentMethods.saveContentItem()** - Creates a single new content item and adds it to a batch
184
- - **contentMethods.saveContentItems()** - Creates multiple new content items and adds them to a batch
185
- - **pageMethods.savePage()** - Creates a new page and adds it to a batch
186
- - These methods create the content AND automatically handle batch creation/management
187
-
188
- #### Batch Workflow Operations (Handled by Batch Controller)
189
- - **batchMethods.publishBatch()** - Publishes all items in an existing batch
190
- - **batchMethods.unpublishBatch()** - Unpublishes all items in an existing batch
191
- - **batchMethods.approveBatch()** - Approves all items in an existing batch
192
- - **batchMethods.declineBatch()** - Declines all items in an existing batch
193
- - **batchMethods.requestApprovalBatch()** - Requests approval for all items in an existing batch
194
- - **batchMethods.getBatch()** - Retrieves details of an existing batch
195
- - **batchMethods.getBatchTypes()** - Retrieves all batch-related enum types for developer discovery
196
-
197
- ### Complete Workflow Example
198
-
199
- ```typescript
200
- import * as mgmtApi from '@agility/management-sdk';
201
-
202
- // Authenticate with simple OAuth flow
203
- const client = new mgmtApi.ApiClient();
204
- await client.auth();
205
-
206
- const guid = 'your-instance-guid';
207
- const locale = 'en-us';
208
-
209
- // Get batch types for dynamic UI and validation
210
- const batchTypes = await client.batchMethods.getBatchTypes(guid);
211
- console.log('Available batch types loaded:', batchTypes);
212
-
213
- // Create NEW content items (handled by content controller)
214
- // This automatically creates and manages batches
215
- const newContentBatchID = await client.contentMethods.saveContentItem(locale, {
216
- properties: {
217
- referenceName: 'blog-post',
218
- definitionName: 'BlogPost',
219
- state: 2
220
- },
221
- fields: {
222
- title: 'My New Blog Post',
223
- content: 'This is the blog post content...'
224
- }
225
- });
226
-
227
- // Create NEW page (handled by page controller)
228
- // This automatically creates and manages batches
229
- const newPageBatchID = await client.pageMethods.savePage(locale, {
230
- name: 'new-product-page',
231
- title: 'New Product Page',
232
- menuText: 'New Product',
233
- pageType: 'static',
234
- templateName: 'Product Template',
235
- parentPageID: -1
236
- });
237
-
238
- // Retrieve details of an existing batch
239
- const batchDetails = await client.batchMethods.getBatch(newContentBatchID, guid);
240
- console.log('Batch details:', batchDetails);
241
-
242
- // Perform workflow operations on existing batches
243
- await client.batchMethods.publishBatch(newContentBatchID, guid);
244
- await client.batchMethods.approveBatch(newPageBatchID, guid);
245
-
246
- // Or use immediate return for custom polling
247
- const batchId = await client.batchMethods.publishBatch(newContentBatchID, guid, true);
248
- console.log('Batch submitted for publishing:', batchId);
249
-
250
- console.log('All operations completed successfully!');
251
- ```
252
-
253
- ### Batch Workflow Operations
254
-
255
- Perform workflow operations (publish, unpublish, approve, decline, request approval) on multiple content items or pages in a single operation using the `WorkflowOperationType` enum:
256
-
257
- ```typescript
258
- import * as mgmtApi from '@agility/management-sdk';
259
- import { WorkflowOperationType } from '@agility/management-sdk';
260
-
261
- const options = new mgmtApi.Options();
262
- options.token = 'your-access-token';
263
- const client = new mgmtApi.ApiClient(options);
264
-
265
- const guid = 'your-instance-guid';
266
- const locale = 'en-us';
267
-
268
- // Batch publish multiple content items
269
- const contentIDs = [101, 102, 103];
270
- const publishedContentIDs = await client.contentMethods.batchWorkflowContent(
271
- contentIDs, guid, locale, WorkflowOperationType.Publish
272
- );
273
- console.log('Published content IDs:', publishedContentIDs);
274
-
275
- // Batch unpublish multiple content items
276
- const unpublishedContentIDs = await client.contentMethods.batchWorkflowContent(
277
- contentIDs, guid, locale, WorkflowOperationType.Unpublish
278
- );
279
- console.log('Unpublished content IDs:', unpublishedContentIDs);
280
-
281
- // Batch approve multiple content items
282
- const approvedContentIDs = await client.contentMethods.batchWorkflowContent(
283
- contentIDs, guid, locale, WorkflowOperationType.Approve
284
- );
285
- console.log('Approved content IDs:', approvedContentIDs);
286
-
287
- // Batch publish multiple pages
288
- const pageIDs = [201, 202, 203];
289
- const publishedPageIDs = await client.pageMethods.batchWorkflowPages(
290
- pageIDs, guid, locale, WorkflowOperationType.Publish
291
- );
292
- console.log('Published page IDs:', publishedPageIDs);
293
-
294
- // Batch unpublish multiple pages
295
- const unpublishedPageIDs = await client.pageMethods.batchWorkflowPages(
296
- pageIDs, guid, locale, WorkflowOperationType.Unpublish
297
- );
298
- console.log('Unpublished page IDs:', unpublishedPageIDs);
299
-
300
- // Get batch ID immediately for custom polling (optional 5th parameter)
301
- const [batchId] = await client.contentMethods.batchWorkflowContent(
302
- contentIDs, guid, locale, WorkflowOperationType.Publish, true
303
- );
304
- console.log('Batch submitted, ID:', batchId);
305
- ```
306
-
307
- ## TypeScript Interfaces
308
-
309
- ### Batch Response Interfaces
310
-
311
- ```typescript
312
- interface BatchTypesResponse {
313
- itemTypes: EnumInfo[]; // Page, ContentItem, ContentList, Tag, ModuleDef
314
- operationTypes: EnumInfo[]; // All operation types
315
- workflowOperations: EnumInfo[]; // Publish, Unpublish, Approve, Decline, RequestApproval
316
- states: EnumInfo[]; // None, Pending, InProcess, Processed, Deleted
317
- }
318
-
319
- interface EnumInfo {
320
- value: number; // Numeric enum value
321
- name: string; // String name (e.g., "Publish")
322
- description: string; // Human-readable description
323
- }
324
- ```
325
-
326
- ## Available Enums
327
-
328
- ### WorkflowOperationType (for batch processing)
329
- > **Note**: In the API documentation (Swagger UI), these operations appear as descriptive dropdown options (Publish, Unpublish, Approve, Decline, RequestApproval) instead of numbers.
330
-
331
- - `Publish = 1`
332
- - `Unpublish = 2`
333
- - `Approve = 3`
334
- - `Decline = 4`
335
- - `RequestApproval = 5`
336
-
337
- ### BatchItemType
338
- > **Note**: In the API documentation (Swagger UI), these appear as descriptive dropdown options (Page, ContentItem, ContentList, Tag, ModuleDef) instead of numbers.
339
-
340
- - `Page = 1`
341
- - `ContentItem = 2`
342
- - `ContentList = 3`
343
- - `Tag = 4`
344
- - `ModuleDef = 5`
345
-
346
- ### BatchState
347
- > **Note**: In the API documentation (Swagger UI), these appear as descriptive names (None, Pending, InProcess, Processed, Deleted) instead of numbers.
348
-
349
- - `None = 0` - Batch created but not submitted for processing
350
- - `Pending = 1` - Batch is pending processing
351
- - `InProcess = 2` - Batch is currently being processed
352
- - `Processed = 3` - Batch has been processed successfully
353
- - `Deleted = 4` - Batch has been deleted
354
-
355
- ## Error Handling
356
-
357
- All methods throw exceptions on failure:
358
-
359
- ```typescript
360
- try {
361
- const batch = await client.batchMethods.getBatch(123, 'instance-guid');
362
- } catch (error) {
363
- console.error('Failed to get batch:', error.message);
364
- }
365
- ```
366
-
367
- ## License
368
-
369
- MIT
370
-
371
- If you have feedback or questions about this starter, please use the [Github Issues](https://github.com/agility/agility-cms-management-sdk-typescript/issues) on this repo, join our [Community Slack Channel](https://join.slack.com/t/agilitycommunity/shared_invite/enQtNzI2NDc3MzU4Njc2LWI2OTNjZTI3ZGY1NWRiNTYzNmEyNmI0MGZlZTRkYzI3NmRjNzkxYmI5YTZjNTg2ZTk4NGUzNjg5NzY3OWViZGI) or create a post on the [Agility Developer Community](https://help.agilitycms.com/hc/en-us/community/topics).
1
+ # Agility CMS & Management API TypeScript SDK
2
+
3
+ ## Table of Contents
4
+
5
+ - [About the Management API SDK](#about-the-management-api-sdk)
6
+ - [Getting Started](#getting-started)
7
+ - [Authentication & Setup](./docs/auth.md)
8
+ - [API Method Classes](#api-method-classes)
9
+ - [Examples](#examples)
10
+ - [TypeScript Interfaces](#typescript-interfaces)
11
+ - [Available Enums](#available-enums)
12
+
13
+ ---
14
+
15
+ ## About the Management API SDK
16
+
17
+ - Provides a facility to developers to use the new Agility Management API more effectively.
18
+ - Provides methods to perform operations on Assets, Batches, Containers, Content, Models, Pages, and Users.
19
+ - **Content and Page Creation** - Create individual or multiple content items and pages (which automatically get added to batches).
20
+ - **Essential batch workflow operations** - Perform publish, unpublish, approve, decline, and request approval operations on existing batches.
21
+ - Ability to generate Content in bulk for a Website.
22
+ - **Strongly typed TypeScript interfaces** for all batch operations with comprehensive error handling.
23
+
24
+ ## Getting Started
25
+
26
+ ### Prerequisites
27
+ 1. Clone the repository agility-cms-management-sdk-typescript.
28
+ 2. Import the index file to make use of the Options class.
29
+ 3. You will need valid Agility CMS credentials to authenticate and obtain an access token.
30
+
31
+ ### Authentication
32
+ For detailed authentication instructions, including OAuth 2.0 setup, token management, and security best practices, see the **[Authentication & Setup Guide](./docs/auth.md)**.
33
+
34
+ ### Making a Request
35
+
36
+ #### Simple OAuth Authentication (Recommended)
37
+
38
+ 1. First, initiate the authorization flow by making a GET request to the authorization endpoint:
39
+ ```javascript
40
+ const authUrl = 'https://mgmt.aglty.io/oauth/authorize';
41
+
42
+ //if you wish to implement offline access using refresh tokens, use this URL (enables refresh tokens)
43
+ //const authUrl = 'https://mgmt.aglty.io/oauth/authorize?scope=offline-access ';
44
+
45
+ const params = new URLSearchParams({
46
+ response_type: 'code',
47
+ redirect_uri: 'YOUR_REDIRECT_URI',
48
+ state: 'YOUR_STATE',
49
+ scope: 'openid profile email offline_access'
50
+ });
51
+
52
+ // Redirect the user to the authorization URL
53
+ window.location.href = `${authUrl}?${params.toString()}`;
54
+ ```
55
+
56
+ 2. After successful authentication, you'll receive an authorization code at your redirect URI. Use this code to obtain an access token:
57
+ ```javascript
58
+ const response = await fetch('https://mgmt.aglty.io/oauth/token', {
59
+ method: 'POST',
60
+ headers: {
61
+ 'Content-Type': 'application/x-www-form-urlencoded'
62
+ },
63
+ body: new URLSearchParams({
64
+ code: 'YOUR_AUTHORIZATION_CODE'
65
+ })
66
+ });
67
+
68
+ const { access_token, refresh_token, expires_in } = await response.json();
69
+ ```
70
+
71
+ 3. Use the obtained token to initialize the SDK:
72
+ ```javascript
73
+ import * as mgmtApi from "@agility/management-sdk";
74
+
75
+ // Initialize the Options Class with your authentication token
76
+ let options = new mgmtApi.Options();
77
+ options.token = access_token; // Use the token obtained from authentication
78
+
79
+ // Initialize the APIClient Class
80
+ let apiClient = new mgmtApi.ApiClient(options);
81
+
82
+ let guid = "<<Provide the Guid of the Website>>";
83
+ let locale = "<<Provide the locale of the Website>>"; // Example: en-us
84
+
85
+ // Now you can make authenticated requests
86
+ var contentItem = await apiClient.contentMethods.getContentItem(22, guid, locale);
87
+ console.log(JSON.stringify(contentItem));
88
+ ```
89
+
90
+ 4. When the access token expires, use the refresh token to obtain a new access token:
91
+ ```javascript
92
+ const response = await fetch('https://mgmt.aglty.io/oauth/refresh', {
93
+ method: 'POST',
94
+ headers: {
95
+ 'Content-Type': 'application/json'
96
+ },
97
+ body: JSON.stringify({
98
+ refresh_token: 'YOUR_REFRESH_TOKEN'
99
+ })
100
+ });
101
+
102
+ const { access_token, refresh_token, expires_in } = await response.json();
103
+ ```
104
+
105
+
106
+ #### Manual Token Authentication (For CI/CD)
107
+ ```typescript
108
+ import * as mgmtApi from "@agility/management-sdk";
109
+
110
+ // Token-based approach for CI/CD and automated environments
111
+ const options = new mgmtApi.Options();
112
+ options.token = process.env.AGILITY_API_TOKEN;
113
+ const apiClient = new mgmtApi.ApiClient(options);
114
+
115
+ const guid = process.env.AGILITY_GUID;
116
+ const locale = "en-us";
117
+
118
+ const contentItem = await apiClient.contentMethods.getContentItem(22, guid, locale);
119
+ console.log('Content retrieved:', contentItem.fields.title);
120
+ ```
121
+
122
+ > 💡 **Note**: The new OAuth authentication requires `keytar` for secure token storage. See the [Authentication & Setup Guide](./docs/auth.md) for OAuth setup or [CI/CD & Automated Environments](./docs/cicd.md) for token-based authentication.
123
+
124
+ ## API Method Classes
125
+
126
+ ### File and Media Management
127
+ - **[AssetMethods](./docs/asset-methods.md)** - File and media management operations (15 functions)
128
+ - [deleteFile](./docs/asset-methods.md#deletefile), [moveFile](./docs/asset-methods.md#movefile), [getMediaList](./docs/asset-methods.md#getmedialist), [getGalleries](./docs/asset-methods.md#getgalleries), [getGalleryById](./docs/asset-methods.md#getgallerybyid), [getGalleryByName](./docs/asset-methods.md#getgallerybyname), [getDefaultContainer](./docs/asset-methods.md#getdefaultcontainer), [saveGallery](./docs/asset-methods.md#savegallery), [deleteGallery](./docs/asset-methods.md#deletegallery), [getAssetByID](./docs/asset-methods.md#getassetbyid), [getAssetByUrl](./docs/asset-methods.md#getassetbyurl), [upload](./docs/asset-methods.md#upload), [createFolder](./docs/asset-methods.md#createfolder), [deleteFolder](./docs/asset-methods.md#deletefolder), [renameFolder](./docs/asset-methods.md#renamefolder)
129
+
130
+ ### Workflow Operations
131
+ - **[BatchMethods](./docs/batch-methods.md)** - Batch workflow operations (7 functions)
132
+ - [getBatch](./docs/batch-methods.md#getbatch), [publishBatch](./docs/batch-methods.md#publishbatch), [unpublishBatch](./docs/batch-methods.md#unpublishbatch), [approveBatch](./docs/batch-methods.md#approvebatch), [declineBatch](./docs/batch-methods.md#declinebatch), [requestApprovalBatch](./docs/batch-methods.md#requestapprovalbatch), [getBatchTypes](./docs/batch-methods.md#getbatchtypes)
133
+
134
+ ### Content Management
135
+ - **[ContainerMethods](./docs/container-methods.md)** - Container management operations (8 functions)
136
+ - [getContainerByID](./docs/container-methods.md#getcontainerbyid), [getContainersByModel](./docs/container-methods.md#getcontainersbymodel), [getContainerByReferenceName](./docs/container-methods.md#getcontainerbyreferencename), [getContainerSecurity](./docs/container-methods.md#getcontainersecurity), [getContainerList](./docs/container-methods.md#getcontainerlist), [getNotificationList](./docs/container-methods.md#getnotificationlist), [saveContainer](./docs/container-methods.md#savecontainer), [deleteContainer](./docs/container-methods.md#deletecontainer)
137
+
138
+ - **[ContentMethods](./docs/content-methods.md)** - Content item operations (14 functions)
139
+ - [getContentItem](./docs/content-methods.md#getcontentitem), [publishContent](./docs/content-methods.md#publishcontent), [unPublishContent](./docs/content-methods.md#unpublishcontent), [batchWorkflowContent](./docs/content-methods.md#batchworkflowcontent), [contentRequestApproval](./docs/content-methods.md#contentrequestapproval), [approveContent](./docs/content-methods.md#approvecontent), [declineContent](./docs/content-methods.md#declinecontent), [deleteContent](./docs/content-methods.md#deletecontent), [saveContentItem](./docs/content-methods.md#savecontentitem), [saveContentItems](./docs/content-methods.md#savecontentitems), [getContentItems](./docs/content-methods.md#getcontentitems), [getContentList](./docs/content-methods.md#getcontentlist), [getContentHistory](./docs/content-methods.md#getcontenthistory), [getContentComments](./docs/content-methods.md#getcontentcomments)
140
+
141
+ - **[ModelMethods](./docs/model-methods.md)** - Content model operations (6 functions)
142
+ - [getContentModel](./docs/model-methods.md#getcontentmodel), [getModelByReferenceName](./docs/model-methods.md#getmodelbyreferencename), [getContentModules](./docs/model-methods.md#getcontentmodules), [getPageModules](./docs/model-methods.md#getpagemodules), [saveModel](./docs/model-methods.md#savemodel), [deleteModel](./docs/model-methods.md#deletemodel)
143
+
144
+ ### Page Management
145
+ - **[PageMethods](./docs/page-methods.md)** - Page management operations (18 functions)
146
+ - [getPage](./docs/page-methods.md#getpage), [getPageByPath](./docs/page-methods.md#getpagebypath), [getPageHistory](./docs/page-methods.md#getpagehistory), [getPageComments](./docs/page-methods.md#getpagecomments), [getPageList](./docs/page-methods.md#getpagelist), [getPageListByPageTemplateID](./docs/page-methods.md#getpagelistbypagetemplateid), [getPageListByPage](./docs/page-methods.md#getpagelistbypage), [getPageListByPageAndPageTemplateID](./docs/page-methods.md#getpagelistbypageandpagetemplateid), [getPageTree](./docs/page-methods.md#getpagetree), [getPageTemplateList](./docs/page-methods.md#getpagetemplatelist), [getPageSecurity](./docs/page-methods.md#getpagesecurity), [getPageItemTemplateList](./docs/page-methods.md#getpageitemtemplatelist), [getPageContentZones](./docs/page-methods.md#getpagecontentzones), [savePage](./docs/page-methods.md#savepage), [savePageSecurity](./docs/page-methods.md#savepagesecurity), [movePageItem](./docs/page-methods.md#movepageitem), [deletePage](./docs/page-methods.md#deletepage), [batchWorkflowPages](./docs/page-methods.md#batchworkflowpages)
147
+
148
+ ### User Management
149
+ - **[InstanceMethods](./docs/instance-methods.md)** - Instance-level operations (2 functions)
150
+ - [getLocales](./docs/instance-methods.md#getlocales), [getFetchApiStatus](./docs/instance-methods.md#getfetchapistatus)
151
+
152
+ - **[InstanceUserMethods](./docs/instance-user-methods.md)** - Instance user management (3 functions)
153
+ - [getUsers](./docs/instance-user-methods.md#getusers), [saveUser](./docs/instance-user-methods.md#saveuser), [deleteUser](./docs/instance-user-methods.md#deleteuser)
154
+
155
+ - **[ServerUserMethods](./docs/server-user-methods.md)** - Server user operations (2 functions)
156
+ - [me](./docs/server-user-methods.md#me), [you](./docs/server-user-methods.md#you)
157
+
158
+ ### Integration
159
+ - **[WebhookMethods](./docs/webhook-methods.md)** - Webhook management (4 functions)
160
+ - [getWebhook](./docs/webhook-methods.md#getwebhook), [webhookList](./docs/webhook-methods.md#webhooklist), [saveWebhook](./docs/webhook-methods.md#savewebhook), [deleteWebhook](./docs/webhook-methods.md#deletewebhook)
161
+
162
+ ### Multi-Instance Operations
163
+ - **[Multi-Instance Operations](./docs/multi-instance-operations.md)** - Advanced workflows for managing content across multiple instances and locales
164
+ - Configuration-driven content creation across multiple environments
165
+ - Parallel processing and batch operations
166
+ - Performance optimization and error handling
167
+ - Cross-instance synchronization and reporting
168
+
169
+ ### CI/CD & Automation
170
+ - **[CI/CD & Automated Environments](./docs/cicd.md)** - Token-based authentication for automated environments
171
+ - CI/CD pipeline examples (GitHub Actions, GitLab CI, Jenkins)
172
+ - Serverless functions (AWS Lambda, Vercel)
173
+ - Environment configuration and security best practices
174
+ - Token management and rotation
175
+
176
+ ## Examples
177
+
178
+ ### Understanding Agility CMS Batch Architecture
179
+
180
+ Agility CMS uses a simple approach for working with content and batches:
181
+
182
+ #### Content/Page Creation (Handled by Respective Controllers)
183
+ - **contentMethods.saveContentItem()** - Creates a single new content item and adds it to a batch
184
+ - **contentMethods.saveContentItems()** - Creates multiple new content items and adds them to a batch
185
+ - **pageMethods.savePage()** - Creates a new page and adds it to a batch
186
+ - These methods create the content AND automatically handle batch creation/management
187
+
188
+ #### Batch Workflow Operations (Handled by Batch Controller)
189
+ - **batchMethods.publishBatch()** - Publishes all items in an existing batch
190
+ - **batchMethods.unpublishBatch()** - Unpublishes all items in an existing batch
191
+ - **batchMethods.approveBatch()** - Approves all items in an existing batch
192
+ - **batchMethods.declineBatch()** - Declines all items in an existing batch
193
+ - **batchMethods.requestApprovalBatch()** - Requests approval for all items in an existing batch
194
+ - **batchMethods.getBatch()** - Retrieves details of an existing batch
195
+ - **batchMethods.getBatchTypes()** - Retrieves all batch-related enum types for developer discovery
196
+
197
+ ### Complete Workflow Example
198
+
199
+ ```typescript
200
+ import * as mgmtApi from '@agility/management-sdk';
201
+
202
+ // Authenticate with simple OAuth flow
203
+ const client = new mgmtApi.ApiClient();
204
+ await client.auth();
205
+
206
+ const guid = 'your-instance-guid';
207
+ const locale = 'en-us';
208
+
209
+ // Get batch types for dynamic UI and validation
210
+ const batchTypes = await client.batchMethods.getBatchTypes(guid);
211
+ console.log('Available batch types loaded:', batchTypes);
212
+
213
+ // Create NEW content items (handled by content controller)
214
+ // This automatically creates and manages batches
215
+ const newContentBatchID = await client.contentMethods.saveContentItem(locale, {
216
+ properties: {
217
+ referenceName: 'blog-post',
218
+ definitionName: 'BlogPost',
219
+ state: 2
220
+ },
221
+ fields: {
222
+ title: 'My New Blog Post',
223
+ content: 'This is the blog post content...'
224
+ }
225
+ });
226
+
227
+ // Create NEW page (handled by page controller)
228
+ // This automatically creates and manages batches
229
+ const newPageBatchID = await client.pageMethods.savePage(locale, {
230
+ name: 'new-product-page',
231
+ title: 'New Product Page',
232
+ menuText: 'New Product',
233
+ pageType: 'static',
234
+ templateName: 'Product Template',
235
+ parentPageID: -1
236
+ });
237
+
238
+ // Retrieve details of an existing batch
239
+ const batchDetails = await client.batchMethods.getBatch(newContentBatchID, guid);
240
+ console.log('Batch details:', batchDetails);
241
+
242
+ // Perform workflow operations on existing batches
243
+ await client.batchMethods.publishBatch(newContentBatchID, guid);
244
+ await client.batchMethods.approveBatch(newPageBatchID, guid);
245
+
246
+ // Or use immediate return for custom polling
247
+ const batchId = await client.batchMethods.publishBatch(newContentBatchID, guid, true);
248
+ console.log('Batch submitted for publishing:', batchId);
249
+
250
+ console.log('All operations completed successfully!');
251
+ ```
252
+
253
+ ### Batch Workflow Operations
254
+
255
+ Perform workflow operations (publish, unpublish, approve, decline, request approval) on multiple content items or pages in a single operation using the `WorkflowOperationType` enum:
256
+
257
+ ```typescript
258
+ import * as mgmtApi from '@agility/management-sdk';
259
+ import { WorkflowOperationType } from '@agility/management-sdk';
260
+
261
+ const options = new mgmtApi.Options();
262
+ options.token = 'your-access-token';
263
+ const client = new mgmtApi.ApiClient(options);
264
+
265
+ const guid = 'your-instance-guid';
266
+ const locale = 'en-us';
267
+
268
+ // Batch publish multiple content items
269
+ const contentIDs = [101, 102, 103];
270
+ const publishedContentIDs = await client.contentMethods.batchWorkflowContent(
271
+ contentIDs, guid, locale, WorkflowOperationType.Publish
272
+ );
273
+ console.log('Published content IDs:', publishedContentIDs);
274
+
275
+ // Batch unpublish multiple content items
276
+ const unpublishedContentIDs = await client.contentMethods.batchWorkflowContent(
277
+ contentIDs, guid, locale, WorkflowOperationType.Unpublish
278
+ );
279
+ console.log('Unpublished content IDs:', unpublishedContentIDs);
280
+
281
+ // Batch approve multiple content items
282
+ const approvedContentIDs = await client.contentMethods.batchWorkflowContent(
283
+ contentIDs, guid, locale, WorkflowOperationType.Approve
284
+ );
285
+ console.log('Approved content IDs:', approvedContentIDs);
286
+
287
+ // Batch publish multiple pages
288
+ const pageIDs = [201, 202, 203];
289
+ const publishedPageIDs = await client.pageMethods.batchWorkflowPages(
290
+ pageIDs, guid, locale, WorkflowOperationType.Publish
291
+ );
292
+ console.log('Published page IDs:', publishedPageIDs);
293
+
294
+ // Batch unpublish multiple pages
295
+ const unpublishedPageIDs = await client.pageMethods.batchWorkflowPages(
296
+ pageIDs, guid, locale, WorkflowOperationType.Unpublish
297
+ );
298
+ console.log('Unpublished page IDs:', unpublishedPageIDs);
299
+
300
+ // Get batch ID immediately for custom polling (optional 5th parameter)
301
+ const [batchId] = await client.contentMethods.batchWorkflowContent(
302
+ contentIDs, guid, locale, WorkflowOperationType.Publish, true
303
+ );
304
+ console.log('Batch submitted, ID:', batchId);
305
+ ```
306
+
307
+ ### Checking Fetch API Sync Status
308
+
309
+ After batch operations, you may want to verify that changes have propagated to the Fetch API CDN before using the content on your frontend:
310
+
311
+ ```typescript
312
+ import * as mgmtApi from '@agility/management-sdk';
313
+
314
+ const options = new mgmtApi.Options();
315
+ options.token = 'your-access-token';
316
+ const client = new mgmtApi.ApiClient(options);
317
+
318
+ const guid = 'your-instance-guid';
319
+
320
+ // After a batch publish operation, wait for CDN sync
321
+ await client.batchMethods.publishBatch(batchId, guid);
322
+
323
+ // Wait for sync to complete
324
+ await client.instanceMethods.getFetchApiStatus(guid, 'fetch', true);
325
+ console.log('Sync complete! Content is now available on the CDN');
326
+
327
+ // Or just check current status without waiting
328
+ const status = await client.instanceMethods.getFetchApiStatus(guid);
329
+ console.log('Sync in progress:', status.inProgress);
330
+ ```
331
+
332
+ ## TypeScript Interfaces
333
+
334
+ ### Batch Response Interfaces
335
+
336
+ ```typescript
337
+ interface BatchTypesResponse {
338
+ itemTypes: EnumInfo[]; // Page, ContentItem, ContentList, Tag, ModuleDef
339
+ operationTypes: EnumInfo[]; // All operation types
340
+ workflowOperations: EnumInfo[]; // Publish, Unpublish, Approve, Decline, RequestApproval
341
+ states: EnumInfo[]; // None, Pending, InProcess, Processed, Deleted
342
+ }
343
+
344
+ interface EnumInfo {
345
+ value: number; // Numeric enum value
346
+ name: string; // String name (e.g., "Publish")
347
+ description: string; // Human-readable description
348
+ }
349
+ ```
350
+
351
+ ## Available Enums
352
+
353
+ ### WorkflowOperationType (for batch processing)
354
+ > **Note**: In the API documentation (Swagger UI), these operations appear as descriptive dropdown options (Publish, Unpublish, Approve, Decline, RequestApproval) instead of numbers.
355
+
356
+ - `Publish = 1`
357
+ - `Unpublish = 2`
358
+ - `Approve = 3`
359
+ - `Decline = 4`
360
+ - `RequestApproval = 5`
361
+
362
+ ### BatchItemType
363
+ > **Note**: In the API documentation (Swagger UI), these appear as descriptive dropdown options (Page, ContentItem, ContentList, Tag, ModuleDef) instead of numbers.
364
+
365
+ - `Page = 1`
366
+ - `ContentItem = 2`
367
+ - `ContentList = 3`
368
+ - `Tag = 4`
369
+ - `ModuleDef = 5`
370
+
371
+ ### BatchState
372
+ > **Note**: In the API documentation (Swagger UI), these appear as descriptive names (None, Pending, InProcess, Processed, Deleted) instead of numbers.
373
+
374
+ - `None = 0` - Batch created but not submitted for processing
375
+ - `Pending = 1` - Batch is pending processing
376
+ - `InProcess = 2` - Batch is currently being processed
377
+ - `Processed = 3` - Batch has been processed successfully
378
+ - `Deleted = 4` - Batch has been deleted
379
+
380
+ ## Error Handling
381
+
382
+ All methods throw exceptions on failure:
383
+
384
+ ```typescript
385
+ try {
386
+ const batch = await client.batchMethods.getBatch(123, 'instance-guid');
387
+ } catch (error) {
388
+ console.error('Failed to get batch:', error.message);
389
+ }
390
+ ```
391
+
392
+ ## License
393
+
394
+ MIT
395
+
396
+ If you have feedback or questions about this starter, please use the [Github Issues](https://github.com/agility/agility-cms-management-sdk-typescript/issues) on this repo, join our [Community Slack Channel](https://join.slack.com/t/agilitycommunity/shared_invite/enQtNzI2NDc3MzU4Njc2LWI2OTNjZTI3ZGY1NWRiNTYzNmEyNmI0MGZlZTRkYzI3NmRjNzkxYmI5YTZjNTg2ZTk4NGUzNjg5NzY3OWViZGI) or create a post on the [Agility Developer Community](https://help.agilitycms.com/hc/en-us/community/topics).