• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-node-sdk / 19555963099

20 Nov 2025 03:38PM UTC coverage: 40.654% (-54.5%) from 95.198%
19555963099

push

github

web-flow
docs: Update Readme for migrating `sdk-gen` to main (box/box-codegen#889) (#1212)

4525 of 19644 branches covered (23.04%)

Branch coverage included in aggregate %.

16708 of 32584 relevant lines covered (51.28%)

140.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.55
/src/managers/groups.ts
1
import { serializeGroups } from '../schemas/groups';
2
import { deserializeGroups } from '../schemas/groups';
237✔
3
import { serializeClientError } from '../schemas/clientError';
4
import { deserializeClientError } from '../schemas/clientError';
5
import { serializeGroupFull } from '../schemas/groupFull';
6
import { deserializeGroupFull } from '../schemas/groupFull';
237✔
7
import { ResponseFormat } from '../networking/fetchOptions';
8
import { Groups } from '../schemas/groups';
9
import { ClientError } from '../schemas/clientError';
10
import { GroupFull } from '../schemas/groupFull';
11
import { BoxSdkError } from '../box/errors';
237✔
12
import { Authentication } from '../networking/auth';
13
import { NetworkSession } from '../networking/network';
237✔
14
import { FetchOptions } from '../networking/fetchOptions';
237✔
15
import { FetchResponse } from '../networking/fetchResponse';
16
import { prepareParams } from '../internal/utils';
237✔
17
import { toString } from '../internal/utils';
237✔
18
import { ByteStream } from '../internal/utils';
19
import { CancellationToken } from '../internal/utils';
20
import { sdToJson } from '../serialization/json';
21
import { SerializedData } from '../serialization/json';
22
import { sdIsEmpty } from '../serialization/json';
23
import { sdIsBoolean } from '../serialization/json';
24
import { sdIsNumber } from '../serialization/json';
25
import { sdIsString } from '../serialization/json';
237✔
26
import { sdIsList } from '../serialization/json';
27
import { sdIsMap } from '../serialization/json';
237✔
28
export class CreateGroupOptionals {
237✔
29
  readonly queryParams: CreateGroupQueryParams =
12✔
30
    {} satisfies CreateGroupQueryParams;
31
  readonly headers: CreateGroupHeaders = new CreateGroupHeaders({});
12✔
32
  readonly cancellationToken?: CancellationToken = void 0;
12✔
33
  constructor(
34
    fields: Omit<
35
      CreateGroupOptionals,
36
      'queryParams' | 'headers' | 'cancellationToken'
37
    > &
38
      Partial<
39
        Pick<
40
          CreateGroupOptionals,
41
          'queryParams' | 'headers' | 'cancellationToken'
42
        >
43
      >,
44
  ) {
45
    if (fields.queryParams !== undefined) {
12!
46
      this.queryParams = fields.queryParams;
×
47
    }
48
    if (fields.headers !== undefined) {
12!
49
      this.headers = fields.headers;
×
50
    }
51
    if (fields.cancellationToken !== undefined) {
12!
52
      this.cancellationToken = fields.cancellationToken;
×
53
    }
54
  }
55
}
56
export interface CreateGroupOptionalsInput {
57
  readonly queryParams?: CreateGroupQueryParams;
58
  readonly headers?: CreateGroupHeaders;
59
  readonly cancellationToken?: undefined | CancellationToken;
60
}
61
export class GetGroupByIdOptionals {
237✔
62
  readonly queryParams: GetGroupByIdQueryParams =
6✔
63
    {} satisfies GetGroupByIdQueryParams;
64
  readonly headers: GetGroupByIdHeaders = new GetGroupByIdHeaders({});
6✔
65
  readonly cancellationToken?: CancellationToken = void 0;
6✔
66
  constructor(
67
    fields: Omit<
68
      GetGroupByIdOptionals,
69
      'queryParams' | 'headers' | 'cancellationToken'
70
    > &
71
      Partial<
72
        Pick<
73
          GetGroupByIdOptionals,
74
          'queryParams' | 'headers' | 'cancellationToken'
75
        >
76
      >,
77
  ) {
78
    if (fields.queryParams !== undefined) {
6✔
79
      this.queryParams = fields.queryParams;
3✔
80
    }
81
    if (fields.headers !== undefined) {
6!
82
      this.headers = fields.headers;
×
83
    }
84
    if (fields.cancellationToken !== undefined) {
6!
85
      this.cancellationToken = fields.cancellationToken;
×
86
    }
87
  }
88
}
89
export interface GetGroupByIdOptionalsInput {
90
  readonly queryParams?: GetGroupByIdQueryParams;
91
  readonly headers?: GetGroupByIdHeaders;
92
  readonly cancellationToken?: undefined | CancellationToken;
93
}
94
export class UpdateGroupByIdOptionals {
237✔
95
  readonly requestBody: UpdateGroupByIdRequestBody =
3✔
96
    {} satisfies UpdateGroupByIdRequestBody;
97
  readonly queryParams: UpdateGroupByIdQueryParams =
3✔
98
    {} satisfies UpdateGroupByIdQueryParams;
99
  readonly headers: UpdateGroupByIdHeaders = new UpdateGroupByIdHeaders({});
3✔
100
  readonly cancellationToken?: CancellationToken = void 0;
3✔
101
  constructor(
102
    fields: Omit<
103
      UpdateGroupByIdOptionals,
104
      'requestBody' | 'queryParams' | 'headers' | 'cancellationToken'
105
    > &
106
      Partial<
107
        Pick<
108
          UpdateGroupByIdOptionals,
109
          'requestBody' | 'queryParams' | 'headers' | 'cancellationToken'
110
        >
111
      >,
112
  ) {
113
    if (fields.requestBody !== undefined) {
3✔
114
      this.requestBody = fields.requestBody;
3✔
115
    }
116
    if (fields.queryParams !== undefined) {
3!
117
      this.queryParams = fields.queryParams;
×
118
    }
119
    if (fields.headers !== undefined) {
3!
120
      this.headers = fields.headers;
×
121
    }
122
    if (fields.cancellationToken !== undefined) {
3!
123
      this.cancellationToken = fields.cancellationToken;
×
124
    }
125
  }
126
}
127
export interface UpdateGroupByIdOptionalsInput {
128
  readonly requestBody?: UpdateGroupByIdRequestBody;
129
  readonly queryParams?: UpdateGroupByIdQueryParams;
130
  readonly headers?: UpdateGroupByIdHeaders;
131
  readonly cancellationToken?: undefined | CancellationToken;
132
}
133
export class DeleteGroupByIdOptionals {
237✔
134
  readonly headers: DeleteGroupByIdHeaders = new DeleteGroupByIdHeaders({});
12✔
135
  readonly cancellationToken?: CancellationToken = void 0;
12✔
136
  constructor(
137
    fields: Omit<DeleteGroupByIdOptionals, 'headers' | 'cancellationToken'> &
138
      Partial<Pick<DeleteGroupByIdOptionals, 'headers' | 'cancellationToken'>>,
139
  ) {
140
    if (fields.headers !== undefined) {
12!
141
      this.headers = fields.headers;
×
142
    }
143
    if (fields.cancellationToken !== undefined) {
12!
144
      this.cancellationToken = fields.cancellationToken;
×
145
    }
146
  }
147
}
148
export interface DeleteGroupByIdOptionalsInput {
149
  readonly headers?: DeleteGroupByIdHeaders;
150
  readonly cancellationToken?: undefined | CancellationToken;
151
}
152
export interface GetGroupsQueryParams {
153
  /**
154
   * Limits the results to only groups whose `name` starts
155
   * with the search term. */
156
  readonly filterTerm?: string;
157
  /**
158
   * A comma-separated list of attributes to include in the
159
   * response. This can be used to request fields that are
160
   * not normally returned in a standard response.
161
   *
162
   * Be aware that specifying this parameter will have the
163
   * effect that none of the standard fields are returned in
164
   * the response unless explicitly specified, instead only
165
   * fields for the mini representation are returned, additional
166
   * to the fields requested. */
167
  readonly fields?: readonly string[];
168
  /**
169
   * The maximum number of items to return per page. */
170
  readonly limit?: number;
171
  /**
172
   * The offset of the item at which to begin the response.
173
   *
174
   * Queries with offset parameter value
175
   * exceeding 10000 will be rejected
176
   * with a 400 response. */
177
  readonly offset?: number;
178
}
179
export class GetGroupsHeaders {
237✔
180
  /**
181
   * Extra headers that will be included in the HTTP request. */
182
  readonly extraHeaders?: {
6✔
183
    readonly [key: string]: undefined | string;
184
  } = {};
185
  constructor(
186
    fields: Omit<GetGroupsHeaders, 'extraHeaders'> &
187
      Partial<Pick<GetGroupsHeaders, 'extraHeaders'>>,
188
  ) {
189
    if (fields.extraHeaders !== undefined) {
6✔
190
      this.extraHeaders = fields.extraHeaders;
3✔
191
    }
192
  }
193
}
194
export interface GetGroupsHeadersInput {
195
  /**
196
   * Extra headers that will be included in the HTTP request. */
197
  readonly extraHeaders?:
198
    | undefined
199
    | {
200
        readonly [key: string]: undefined | string;
201
      };
202
}
203
export type CreateGroupRequestBodyInvitabilityLevelField =
204
  | 'admins_only'
205
  | 'admins_and_members'
206
  | 'all_managed_users'
207
  | string;
208
export type CreateGroupRequestBodyMemberViewabilityLevelField =
209
  | 'admins_only'
210
  | 'admins_and_members'
211
  | 'all_managed_users'
212
  | string;
213
export interface CreateGroupRequestBody {
214
  /**
215
   * The name of the new group to be created. This name must be unique
216
   * within the enterprise. */
217
  readonly name: string;
218
  /**
219
   * Keeps track of which external source this group is
220
   * coming, for example `Active Directory`, or `Okta`.
221
   *
222
   * Setting this will also prevent Box admins from editing
223
   * the group name and its members directly via the Box
224
   * web application.
225
   *
226
   * This is desirable for one-way syncing of groups. */
227
  readonly provenance?: string;
228
  /**
229
   * An arbitrary identifier that can be used by
230
   * external group sync tools to link this Box Group to
231
   * an external group.
232
   *
233
   * Example values of this field
234
   * could be an **Active Directory Object ID** or a **Google
235
   * Group ID**.
236
   *
237
   * We recommend you use of this field in
238
   * order to avoid issues when group names are updated in
239
   * either Box or external systems. */
240
  readonly externalSyncIdentifier?: string;
241
  /**
242
   * A human readable description of the group. */
243
  readonly description?: string;
244
  /**
245
   * Specifies who can invite the group to collaborate
246
   * on folders.
247
   *
248
   * When set to `admins_only` the enterprise admin, co-admins,
249
   * and the group's admin can invite the group.
250
   *
251
   * When set to `admins_and_members` all the admins listed
252
   * above and group members can invite the group.
253
   *
254
   * When set to `all_managed_users` all managed users in the
255
   * enterprise can invite the group. */
256
  readonly invitabilityLevel?: CreateGroupRequestBodyInvitabilityLevelField;
257
  /**
258
   * Specifies who can see the members of the group.
259
   *
260
   * * `admins_only` - the enterprise admin, co-admins, group's
261
   *   group admin.
262
   * * `admins_and_members` - all admins and group members.
263
   * * `all_managed_users` - all managed users in the
264
   *   enterprise. */
265
  readonly memberViewabilityLevel?: CreateGroupRequestBodyMemberViewabilityLevelField;
266
  readonly rawData?: SerializedData;
267
}
268
export interface CreateGroupQueryParams {
269
  /**
270
   * A comma-separated list of attributes to include in the
271
   * response. This can be used to request fields that are
272
   * not normally returned in a standard response.
273
   *
274
   * Be aware that specifying this parameter will have the
275
   * effect that none of the standard fields are returned in
276
   * the response unless explicitly specified, instead only
277
   * fields for the mini representation are returned, additional
278
   * to the fields requested. */
279
  readonly fields?: readonly string[];
280
}
281
export class CreateGroupHeaders {
237✔
282
  /**
283
   * Extra headers that will be included in the HTTP request. */
284
  readonly extraHeaders?: {
12✔
285
    readonly [key: string]: undefined | string;
286
  } = {};
287
  constructor(
288
    fields: Omit<CreateGroupHeaders, 'extraHeaders'> &
289
      Partial<Pick<CreateGroupHeaders, 'extraHeaders'>>,
290
  ) {
291
    if (fields.extraHeaders !== undefined) {
12!
292
      this.extraHeaders = fields.extraHeaders;
×
293
    }
294
  }
295
}
296
export interface CreateGroupHeadersInput {
297
  /**
298
   * Extra headers that will be included in the HTTP request. */
299
  readonly extraHeaders?:
300
    | undefined
301
    | {
302
        readonly [key: string]: undefined | string;
303
      };
304
}
305
export interface GetGroupByIdQueryParams {
306
  /**
307
   * A comma-separated list of attributes to include in the
308
   * response. This can be used to request fields that are
309
   * not normally returned in a standard response.
310
   *
311
   * Be aware that specifying this parameter will have the
312
   * effect that none of the standard fields are returned in
313
   * the response unless explicitly specified, instead only
314
   * fields for the mini representation are returned, additional
315
   * to the fields requested. */
316
  readonly fields?: readonly string[];
317
}
318
export class GetGroupByIdHeaders {
237✔
319
  /**
320
   * Extra headers that will be included in the HTTP request. */
321
  readonly extraHeaders?: {
6✔
322
    readonly [key: string]: undefined | string;
323
  } = {};
324
  constructor(
325
    fields: Omit<GetGroupByIdHeaders, 'extraHeaders'> &
326
      Partial<Pick<GetGroupByIdHeaders, 'extraHeaders'>>,
327
  ) {
328
    if (fields.extraHeaders !== undefined) {
6!
329
      this.extraHeaders = fields.extraHeaders;
×
330
    }
331
  }
332
}
333
export interface GetGroupByIdHeadersInput {
334
  /**
335
   * Extra headers that will be included in the HTTP request. */
336
  readonly extraHeaders?:
337
    | undefined
338
    | {
339
        readonly [key: string]: undefined | string;
340
      };
341
}
342
export type UpdateGroupByIdRequestBodyInvitabilityLevelField =
343
  | 'admins_only'
344
  | 'admins_and_members'
345
  | 'all_managed_users'
346
  | string;
347
export type UpdateGroupByIdRequestBodyMemberViewabilityLevelField =
348
  | 'admins_only'
349
  | 'admins_and_members'
350
  | 'all_managed_users'
351
  | string;
352
export interface UpdateGroupByIdRequestBody {
353
  /**
354
   * The name of the new group to be created. Must be unique within the
355
   * enterprise. */
356
  readonly name?: string;
357
  /**
358
   * Keeps track of which external source this group is
359
   * coming, for example `Active Directory`, or `Okta`.
360
   *
361
   * Setting this will also prevent Box admins from editing
362
   * the group name and its members directly via the Box
363
   * web application.
364
   *
365
   * This is desirable for one-way syncing of groups. */
366
  readonly provenance?: string;
367
  /**
368
   * An arbitrary identifier that can be used by
369
   * external group sync tools to link this Box Group to
370
   * an external group.
371
   *
372
   * Example values of this field
373
   * could be an **Active Directory Object ID** or a **Google
374
   * Group ID**.
375
   *
376
   * We recommend you use of this field in
377
   * order to avoid issues when group names are updated in
378
   * either Box or external systems. */
379
  readonly externalSyncIdentifier?: string;
380
  /**
381
   * A human readable description of the group. */
382
  readonly description?: string;
383
  /**
384
   * Specifies who can invite the group to collaborate
385
   * on folders.
386
   *
387
   * When set to `admins_only` the enterprise admin, co-admins,
388
   * and the group's admin can invite the group.
389
   *
390
   * When set to `admins_and_members` all the admins listed
391
   * above and group members can invite the group.
392
   *
393
   * When set to `all_managed_users` all managed users in the
394
   * enterprise can invite the group. */
395
  readonly invitabilityLevel?: UpdateGroupByIdRequestBodyInvitabilityLevelField;
396
  /**
397
   * Specifies who can see the members of the group.
398
   *
399
   * * `admins_only` - the enterprise admin, co-admins, group's
400
   *   group admin.
401
   * * `admins_and_members` - all admins and group members.
402
   * * `all_managed_users` - all managed users in the
403
   *   enterprise. */
404
  readonly memberViewabilityLevel?: UpdateGroupByIdRequestBodyMemberViewabilityLevelField;
405
  readonly rawData?: SerializedData;
406
}
407
export interface UpdateGroupByIdQueryParams {
408
  /**
409
   * A comma-separated list of attributes to include in the
410
   * response. This can be used to request fields that are
411
   * not normally returned in a standard response.
412
   *
413
   * Be aware that specifying this parameter will have the
414
   * effect that none of the standard fields are returned in
415
   * the response unless explicitly specified, instead only
416
   * fields for the mini representation are returned, additional
417
   * to the fields requested. */
418
  readonly fields?: readonly string[];
419
}
420
export class UpdateGroupByIdHeaders {
237✔
421
  /**
422
   * Extra headers that will be included in the HTTP request. */
423
  readonly extraHeaders?: {
3✔
424
    readonly [key: string]: undefined | string;
425
  } = {};
426
  constructor(
427
    fields: Omit<UpdateGroupByIdHeaders, 'extraHeaders'> &
428
      Partial<Pick<UpdateGroupByIdHeaders, 'extraHeaders'>>,
429
  ) {
430
    if (fields.extraHeaders !== undefined) {
3!
431
      this.extraHeaders = fields.extraHeaders;
×
432
    }
433
  }
434
}
435
export interface UpdateGroupByIdHeadersInput {
436
  /**
437
   * Extra headers that will be included in the HTTP request. */
438
  readonly extraHeaders?:
439
    | undefined
440
    | {
441
        readonly [key: string]: undefined | string;
442
      };
443
}
444
export class DeleteGroupByIdHeaders {
237✔
445
  /**
446
   * Extra headers that will be included in the HTTP request. */
447
  readonly extraHeaders?: {
12✔
448
    readonly [key: string]: undefined | string;
449
  } = {};
450
  constructor(
451
    fields: Omit<DeleteGroupByIdHeaders, 'extraHeaders'> &
452
      Partial<Pick<DeleteGroupByIdHeaders, 'extraHeaders'>>,
453
  ) {
454
    if (fields.extraHeaders !== undefined) {
12!
455
      this.extraHeaders = fields.extraHeaders;
×
456
    }
457
  }
458
}
459
export interface DeleteGroupByIdHeadersInput {
460
  /**
461
   * Extra headers that will be included in the HTTP request. */
462
  readonly extraHeaders?:
463
    | undefined
464
    | {
465
        readonly [key: string]: undefined | string;
466
      };
467
}
468
export class GroupsManager {
237✔
469
  readonly auth?: Authentication;
470
  readonly networkSession: NetworkSession = new NetworkSession({});
510✔
471
  constructor(
472
    fields: Omit<
473
      GroupsManager,
474
      | 'networkSession'
475
      | 'getGroups'
476
      | 'createGroup'
477
      | 'getGroupById'
478
      | 'updateGroupById'
479
      | 'deleteGroupById'
480
    > &
481
      Partial<Pick<GroupsManager, 'networkSession'>>,
482
  ) {
483
    if (fields.auth !== undefined) {
510✔
484
      this.auth = fields.auth;
510✔
485
    }
486
    if (fields.networkSession !== undefined) {
510✔
487
      this.networkSession = fields.networkSession;
510✔
488
    }
489
  }
490
  /**
491
   * Retrieves all of the groups for a given enterprise. The user
492
   * must have admin permissions to inspect enterprise's groups.
493
   * @param {GetGroupsQueryParams} queryParams Query parameters of getGroups method
494
   * @param {GetGroupsHeadersInput} headersInput Headers of getGroups method
495
   * @param {CancellationToken} cancellationToken Token used for request cancellation.
496
   * @returns {Promise<Groups>}
497
   */
498
  async getGroups(
499
    queryParams: GetGroupsQueryParams = {} satisfies GetGroupsQueryParams,
3✔
500
    headersInput: GetGroupsHeadersInput = new GetGroupsHeaders({}),
3✔
501
    cancellationToken?: CancellationToken,
502
  ): Promise<Groups> {
503
    const headers: GetGroupsHeaders = new GetGroupsHeaders({
3✔
504
      extraHeaders: headersInput.extraHeaders,
505
    });
506
    const queryParamsMap: {
507
      readonly [key: string]: string;
508
    } = prepareParams({
3✔
509
      ['filter_term']: toString(queryParams.filterTerm) as string,
510
      ['fields']: queryParams.fields
3!
511
        ? queryParams.fields.map(toString).join(',')
512
        : undefined,
513
      ['limit']: toString(queryParams.limit) as string,
514
      ['offset']: toString(queryParams.offset) as string,
515
    });
516
    const headersMap: {
517
      readonly [key: string]: string;
518
    } = prepareParams({ ...{}, ...headers.extraHeaders });
3✔
519
    const response: FetchResponse =
520
      await this.networkSession.networkClient.fetch(
3✔
521
        new FetchOptions({
522
          url: ''.concat(
523
            this.networkSession.baseUrls.baseUrl,
524
            '/2.0/groups',
525
          ) as string,
526
          method: 'GET',
527
          params: queryParamsMap,
528
          headers: headersMap,
529
          responseFormat: 'json' as ResponseFormat,
530
          auth: this.auth,
531
          networkSession: this.networkSession,
532
          cancellationToken: cancellationToken,
533
        }),
534
      );
535
    return {
3✔
536
      ...deserializeGroups(response.data!),
537
      rawData: response.data!,
538
    };
539
  }
540
  /**
541
   * Creates a new group of users in an enterprise. Only users with admin
542
   * permissions can create new groups.
543
   * @param {CreateGroupRequestBody} requestBody Request body of createGroup method
544
   * @param {CreateGroupOptionalsInput} optionalsInput
545
   * @returns {Promise<GroupFull>}
546
   */
547
  async createGroup(
548
    requestBody: CreateGroupRequestBody,
12✔
549
    optionalsInput: CreateGroupOptionalsInput = {},
12✔
550
  ): Promise<GroupFull> {
551
    const optionals: CreateGroupOptionals = new CreateGroupOptionals({
12✔
552
      queryParams: optionalsInput.queryParams,
553
      headers: optionalsInput.headers,
554
      cancellationToken: optionalsInput.cancellationToken,
555
    });
556
    const queryParams: any = optionals.queryParams;
12✔
557
    const headers: any = optionals.headers;
12✔
558
    const cancellationToken: any = optionals.cancellationToken;
12✔
559
    const queryParamsMap: {
560
      readonly [key: string]: string;
561
    } = prepareParams({
12✔
562
      ['fields']: queryParams.fields
12!
563
        ? queryParams.fields.map(toString).join(',')
564
        : undefined,
565
    });
566
    const headersMap: {
567
      readonly [key: string]: string;
568
    } = prepareParams({ ...{}, ...headers.extraHeaders });
12✔
569
    const response: FetchResponse =
570
      await this.networkSession.networkClient.fetch(
12✔
571
        new FetchOptions({
572
          url: ''.concat(
573
            this.networkSession.baseUrls.baseUrl,
574
            '/2.0/groups',
575
          ) as string,
576
          method: 'POST',
577
          params: queryParamsMap,
578
          headers: headersMap,
579
          data: serializeCreateGroupRequestBody(requestBody),
580
          contentType: 'application/json',
581
          responseFormat: 'json' as ResponseFormat,
582
          auth: this.auth,
583
          networkSession: this.networkSession,
584
          cancellationToken: cancellationToken,
585
        }),
586
      );
587
    return {
12✔
588
      ...deserializeGroupFull(response.data!),
589
      rawData: response.data!,
590
    };
591
  }
592
  /**
593
     * Retrieves information about a group. Only members of this
594
     * group or users with admin-level permissions will be able to
595
     * use this API.
596
     * @param {string} groupId The ID of the group.
597
    Example: "57645"
598
     * @param {GetGroupByIdOptionalsInput} optionalsInput
599
     * @returns {Promise<GroupFull>}
600
     */
601
  async getGroupById(
602
    groupId: string,
6✔
603
    optionalsInput: GetGroupByIdOptionalsInput = {},
3✔
604
  ): Promise<GroupFull> {
605
    const optionals: GetGroupByIdOptionals = new GetGroupByIdOptionals({
6✔
606
      queryParams: optionalsInput.queryParams,
607
      headers: optionalsInput.headers,
608
      cancellationToken: optionalsInput.cancellationToken,
609
    });
610
    const queryParams: any = optionals.queryParams;
6✔
611
    const headers: any = optionals.headers;
6✔
612
    const cancellationToken: any = optionals.cancellationToken;
6✔
613
    const queryParamsMap: {
614
      readonly [key: string]: string;
615
    } = prepareParams({
6✔
616
      ['fields']: queryParams.fields
6✔
617
        ? queryParams.fields.map(toString).join(',')
618
        : undefined,
619
    });
620
    const headersMap: {
621
      readonly [key: string]: string;
622
    } = prepareParams({ ...{}, ...headers.extraHeaders });
6✔
623
    const response: FetchResponse =
624
      await this.networkSession.networkClient.fetch(
6✔
625
        new FetchOptions({
626
          url: ''.concat(
627
            this.networkSession.baseUrls.baseUrl,
628
            '/2.0/groups/',
629
            toString(groupId) as string,
630
          ) as string,
631
          method: 'GET',
632
          params: queryParamsMap,
633
          headers: headersMap,
634
          responseFormat: 'json' as ResponseFormat,
635
          auth: this.auth,
636
          networkSession: this.networkSession,
637
          cancellationToken: cancellationToken,
638
        }),
639
      );
640
    return {
3✔
641
      ...deserializeGroupFull(response.data!),
642
      rawData: response.data!,
643
    };
644
  }
645
  /**
646
     * Updates a specific group. Only admins of this
647
     * group or users with admin-level permissions will be able to
648
     * use this API.
649
     * @param {string} groupId The ID of the group.
650
    Example: "57645"
651
     * @param {UpdateGroupByIdOptionalsInput} optionalsInput
652
     * @returns {Promise<GroupFull>}
653
     */
654
  async updateGroupById(
655
    groupId: string,
3✔
656
    optionalsInput: UpdateGroupByIdOptionalsInput = {},
×
657
  ): Promise<GroupFull> {
658
    const optionals: UpdateGroupByIdOptionals = new UpdateGroupByIdOptionals({
3✔
659
      requestBody: optionalsInput.requestBody,
660
      queryParams: optionalsInput.queryParams,
661
      headers: optionalsInput.headers,
662
      cancellationToken: optionalsInput.cancellationToken,
663
    });
664
    const requestBody: any = optionals.requestBody;
3✔
665
    const queryParams: any = optionals.queryParams;
3✔
666
    const headers: any = optionals.headers;
3✔
667
    const cancellationToken: any = optionals.cancellationToken;
3✔
668
    const queryParamsMap: {
669
      readonly [key: string]: string;
670
    } = prepareParams({
3✔
671
      ['fields']: queryParams.fields
3!
672
        ? queryParams.fields.map(toString).join(',')
673
        : undefined,
674
    });
675
    const headersMap: {
676
      readonly [key: string]: string;
677
    } = prepareParams({ ...{}, ...headers.extraHeaders });
3✔
678
    const response: FetchResponse =
679
      await this.networkSession.networkClient.fetch(
3✔
680
        new FetchOptions({
681
          url: ''.concat(
682
            this.networkSession.baseUrls.baseUrl,
683
            '/2.0/groups/',
684
            toString(groupId) as string,
685
          ) as string,
686
          method: 'PUT',
687
          params: queryParamsMap,
688
          headers: headersMap,
689
          data: serializeUpdateGroupByIdRequestBody(requestBody),
690
          contentType: 'application/json',
691
          responseFormat: 'json' as ResponseFormat,
692
          auth: this.auth,
693
          networkSession: this.networkSession,
694
          cancellationToken: cancellationToken,
695
        }),
696
      );
697
    return {
3✔
698
      ...deserializeGroupFull(response.data!),
699
      rawData: response.data!,
700
    };
701
  }
702
  /**
703
     * Permanently deletes a group. Only users with
704
     * admin-level permissions will be able to use this API.
705
     * @param {string} groupId The ID of the group.
706
    Example: "57645"
707
     * @param {DeleteGroupByIdOptionalsInput} optionalsInput
708
     * @returns {Promise<undefined>}
709
     */
710
  async deleteGroupById(
711
    groupId: string,
12✔
712
    optionalsInput: DeleteGroupByIdOptionalsInput = {},
12✔
713
  ): Promise<undefined> {
714
    const optionals: DeleteGroupByIdOptionals = new DeleteGroupByIdOptionals({
12✔
715
      headers: optionalsInput.headers,
716
      cancellationToken: optionalsInput.cancellationToken,
717
    });
718
    const headers: any = optionals.headers;
12✔
719
    const cancellationToken: any = optionals.cancellationToken;
12✔
720
    const headersMap: {
721
      readonly [key: string]: string;
722
    } = prepareParams({ ...{}, ...headers.extraHeaders });
12✔
723
    const response: FetchResponse =
724
      await this.networkSession.networkClient.fetch(
12✔
725
        new FetchOptions({
726
          url: ''.concat(
727
            this.networkSession.baseUrls.baseUrl,
728
            '/2.0/groups/',
729
            toString(groupId) as string,
730
          ) as string,
731
          method: 'DELETE',
732
          headers: headersMap,
733
          responseFormat: 'no_content' as ResponseFormat,
734
          auth: this.auth,
735
          networkSession: this.networkSession,
736
          cancellationToken: cancellationToken,
737
        }),
738
      );
739
    return void 0;
12✔
740
  }
741
}
742
export interface GroupsManagerInput {
743
  readonly auth?: Authentication;
744
  readonly networkSession?: NetworkSession;
745
}
746
export function serializeCreateGroupRequestBodyInvitabilityLevelField(
237✔
747
  val: CreateGroupRequestBodyInvitabilityLevelField,
748
): SerializedData {
749
  return val;
×
750
}
751
export function deserializeCreateGroupRequestBodyInvitabilityLevelField(
237✔
752
  val: SerializedData,
753
): CreateGroupRequestBodyInvitabilityLevelField {
754
  if (val == 'admins_only') {
×
755
    return val;
×
756
  }
757
  if (val == 'admins_and_members') {
×
758
    return val;
×
759
  }
760
  if (val == 'all_managed_users') {
×
761
    return val;
×
762
  }
763
  if (sdIsString(val)) {
×
764
    return val;
×
765
  }
766
  throw new BoxSdkError({
×
767
    message: "Can't deserialize CreateGroupRequestBodyInvitabilityLevelField",
768
  });
769
}
770
export function serializeCreateGroupRequestBodyMemberViewabilityLevelField(
237✔
771
  val: CreateGroupRequestBodyMemberViewabilityLevelField,
772
): SerializedData {
773
  return val;
×
774
}
775
export function deserializeCreateGroupRequestBodyMemberViewabilityLevelField(
237✔
776
  val: SerializedData,
777
): CreateGroupRequestBodyMemberViewabilityLevelField {
778
  if (val == 'admins_only') {
×
779
    return val;
×
780
  }
781
  if (val == 'admins_and_members') {
×
782
    return val;
×
783
  }
784
  if (val == 'all_managed_users') {
×
785
    return val;
×
786
  }
787
  if (sdIsString(val)) {
×
788
    return val;
×
789
  }
790
  throw new BoxSdkError({
×
791
    message:
792
      "Can't deserialize CreateGroupRequestBodyMemberViewabilityLevelField",
793
  });
794
}
795
export function serializeCreateGroupRequestBody(
237✔
796
  val: CreateGroupRequestBody,
797
): SerializedData {
798
  return {
12✔
799
    ['name']: val.name,
800
    ['provenance']: val.provenance,
801
    ['external_sync_identifier']: val.externalSyncIdentifier,
802
    ['description']: val.description,
803
    ['invitability_level']:
804
      val.invitabilityLevel == void 0
12!
805
        ? val.invitabilityLevel
806
        : serializeCreateGroupRequestBodyInvitabilityLevelField(
807
            val.invitabilityLevel,
808
          ),
809
    ['member_viewability_level']:
810
      val.memberViewabilityLevel == void 0
12!
811
        ? val.memberViewabilityLevel
812
        : serializeCreateGroupRequestBodyMemberViewabilityLevelField(
813
            val.memberViewabilityLevel,
814
          ),
815
  };
816
}
817
export function deserializeCreateGroupRequestBody(
237✔
818
  val: SerializedData,
819
): CreateGroupRequestBody {
820
  if (!sdIsMap(val)) {
×
821
    throw new BoxSdkError({
×
822
      message: 'Expecting a map for "CreateGroupRequestBody"',
823
    });
824
  }
825
  if (val.name == void 0) {
×
826
    throw new BoxSdkError({
×
827
      message:
828
        'Expecting "name" of type "CreateGroupRequestBody" to be defined',
829
    });
830
  }
831
  if (!sdIsString(val.name)) {
×
832
    throw new BoxSdkError({
×
833
      message: 'Expecting string for "name" of type "CreateGroupRequestBody"',
834
    });
835
  }
836
  const name: string = val.name;
×
837
  if (!(val.provenance == void 0) && !sdIsString(val.provenance)) {
×
838
    throw new BoxSdkError({
×
839
      message:
840
        'Expecting string for "provenance" of type "CreateGroupRequestBody"',
841
    });
842
  }
843
  const provenance: undefined | string =
844
    val.provenance == void 0 ? void 0 : val.provenance;
×
845
  if (
×
846
    !(val.external_sync_identifier == void 0) &&
×
847
    !sdIsString(val.external_sync_identifier)
848
  ) {
849
    throw new BoxSdkError({
×
850
      message:
851
        'Expecting string for "external_sync_identifier" of type "CreateGroupRequestBody"',
852
    });
853
  }
854
  const externalSyncIdentifier: undefined | string =
855
    val.external_sync_identifier == void 0
×
856
      ? void 0
857
      : val.external_sync_identifier;
858
  if (!(val.description == void 0) && !sdIsString(val.description)) {
×
859
    throw new BoxSdkError({
×
860
      message:
861
        'Expecting string for "description" of type "CreateGroupRequestBody"',
862
    });
863
  }
864
  const description: undefined | string =
865
    val.description == void 0 ? void 0 : val.description;
×
866
  const invitabilityLevel:
867
    | undefined
868
    | CreateGroupRequestBodyInvitabilityLevelField =
869
    val.invitability_level == void 0
×
870
      ? void 0
871
      : deserializeCreateGroupRequestBodyInvitabilityLevelField(
872
          val.invitability_level,
873
        );
874
  const memberViewabilityLevel:
875
    | undefined
876
    | CreateGroupRequestBodyMemberViewabilityLevelField =
877
    val.member_viewability_level == void 0
×
878
      ? void 0
879
      : deserializeCreateGroupRequestBodyMemberViewabilityLevelField(
880
          val.member_viewability_level,
881
        );
882
  return {
×
883
    name: name,
884
    provenance: provenance,
885
    externalSyncIdentifier: externalSyncIdentifier,
886
    description: description,
887
    invitabilityLevel: invitabilityLevel,
888
    memberViewabilityLevel: memberViewabilityLevel,
889
  } satisfies CreateGroupRequestBody;
890
}
891
export function serializeUpdateGroupByIdRequestBodyInvitabilityLevelField(
237✔
892
  val: UpdateGroupByIdRequestBodyInvitabilityLevelField,
893
): SerializedData {
894
  return val;
×
895
}
896
export function deserializeUpdateGroupByIdRequestBodyInvitabilityLevelField(
237✔
897
  val: SerializedData,
898
): UpdateGroupByIdRequestBodyInvitabilityLevelField {
899
  if (val == 'admins_only') {
×
900
    return val;
×
901
  }
902
  if (val == 'admins_and_members') {
×
903
    return val;
×
904
  }
905
  if (val == 'all_managed_users') {
×
906
    return val;
×
907
  }
908
  if (sdIsString(val)) {
×
909
    return val;
×
910
  }
911
  throw new BoxSdkError({
×
912
    message:
913
      "Can't deserialize UpdateGroupByIdRequestBodyInvitabilityLevelField",
914
  });
915
}
916
export function serializeUpdateGroupByIdRequestBodyMemberViewabilityLevelField(
237✔
917
  val: UpdateGroupByIdRequestBodyMemberViewabilityLevelField,
918
): SerializedData {
919
  return val;
×
920
}
921
export function deserializeUpdateGroupByIdRequestBodyMemberViewabilityLevelField(
237✔
922
  val: SerializedData,
923
): UpdateGroupByIdRequestBodyMemberViewabilityLevelField {
924
  if (val == 'admins_only') {
×
925
    return val;
×
926
  }
927
  if (val == 'admins_and_members') {
×
928
    return val;
×
929
  }
930
  if (val == 'all_managed_users') {
×
931
    return val;
×
932
  }
933
  if (sdIsString(val)) {
×
934
    return val;
×
935
  }
936
  throw new BoxSdkError({
×
937
    message:
938
      "Can't deserialize UpdateGroupByIdRequestBodyMemberViewabilityLevelField",
939
  });
940
}
941
export function serializeUpdateGroupByIdRequestBody(
237✔
942
  val: UpdateGroupByIdRequestBody,
943
): SerializedData {
944
  return {
3✔
945
    ['name']: val.name,
946
    ['provenance']: val.provenance,
947
    ['external_sync_identifier']: val.externalSyncIdentifier,
948
    ['description']: val.description,
949
    ['invitability_level']:
950
      val.invitabilityLevel == void 0
3!
951
        ? val.invitabilityLevel
952
        : serializeUpdateGroupByIdRequestBodyInvitabilityLevelField(
953
            val.invitabilityLevel,
954
          ),
955
    ['member_viewability_level']:
956
      val.memberViewabilityLevel == void 0
3!
957
        ? val.memberViewabilityLevel
958
        : serializeUpdateGroupByIdRequestBodyMemberViewabilityLevelField(
959
            val.memberViewabilityLevel,
960
          ),
961
  };
962
}
963
export function deserializeUpdateGroupByIdRequestBody(
237✔
964
  val: SerializedData,
965
): UpdateGroupByIdRequestBody {
966
  if (!sdIsMap(val)) {
×
967
    throw new BoxSdkError({
×
968
      message: 'Expecting a map for "UpdateGroupByIdRequestBody"',
969
    });
970
  }
971
  if (!(val.name == void 0) && !sdIsString(val.name)) {
×
972
    throw new BoxSdkError({
×
973
      message:
974
        'Expecting string for "name" of type "UpdateGroupByIdRequestBody"',
975
    });
976
  }
977
  const name: undefined | string = val.name == void 0 ? void 0 : val.name;
×
978
  if (!(val.provenance == void 0) && !sdIsString(val.provenance)) {
×
979
    throw new BoxSdkError({
×
980
      message:
981
        'Expecting string for "provenance" of type "UpdateGroupByIdRequestBody"',
982
    });
983
  }
984
  const provenance: undefined | string =
985
    val.provenance == void 0 ? void 0 : val.provenance;
×
986
  if (
×
987
    !(val.external_sync_identifier == void 0) &&
×
988
    !sdIsString(val.external_sync_identifier)
989
  ) {
990
    throw new BoxSdkError({
×
991
      message:
992
        'Expecting string for "external_sync_identifier" of type "UpdateGroupByIdRequestBody"',
993
    });
994
  }
995
  const externalSyncIdentifier: undefined | string =
996
    val.external_sync_identifier == void 0
×
997
      ? void 0
998
      : val.external_sync_identifier;
999
  if (!(val.description == void 0) && !sdIsString(val.description)) {
×
1000
    throw new BoxSdkError({
×
1001
      message:
1002
        'Expecting string for "description" of type "UpdateGroupByIdRequestBody"',
1003
    });
1004
  }
1005
  const description: undefined | string =
1006
    val.description == void 0 ? void 0 : val.description;
×
1007
  const invitabilityLevel:
1008
    | undefined
1009
    | UpdateGroupByIdRequestBodyInvitabilityLevelField =
1010
    val.invitability_level == void 0
×
1011
      ? void 0
1012
      : deserializeUpdateGroupByIdRequestBodyInvitabilityLevelField(
1013
          val.invitability_level,
1014
        );
1015
  const memberViewabilityLevel:
1016
    | undefined
1017
    | UpdateGroupByIdRequestBodyMemberViewabilityLevelField =
1018
    val.member_viewability_level == void 0
×
1019
      ? void 0
1020
      : deserializeUpdateGroupByIdRequestBodyMemberViewabilityLevelField(
1021
          val.member_viewability_level,
1022
        );
1023
  return {
×
1024
    name: name,
1025
    provenance: provenance,
1026
    externalSyncIdentifier: externalSyncIdentifier,
1027
    description: description,
1028
    invitabilityLevel: invitabilityLevel,
1029
    memberViewabilityLevel: memberViewabilityLevel,
1030
  } satisfies UpdateGroupByIdRequestBody;
1031
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc