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

box / box-java-sdk / #5076

07 Oct 2025 12:35PM UTC coverage: 37.132% (+0.007%) from 37.125%
#5076

push

github

web-flow
test: Change `Event.additionalDetails` field assertion in events test (box/box-codegen#858) (#1491)

18454 of 49699 relevant lines covered (37.13%)

0.37 hits per line

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

87.1
/src/main/java/com/box/sdkgen/managers/fileversions/FileVersionsManager.java
1
package com.box.sdkgen.managers.fileversions;
2

3
import static com.box.sdkgen.internal.utils.UtilsManager.convertToString;
4
import static com.box.sdkgen.internal.utils.UtilsManager.entryOf;
5
import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
6
import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps;
7
import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams;
8

9
import com.box.sdkgen.networking.auth.Authentication;
10
import com.box.sdkgen.networking.fetchoptions.FetchOptions;
11
import com.box.sdkgen.networking.fetchoptions.ResponseFormat;
12
import com.box.sdkgen.networking.fetchresponse.FetchResponse;
13
import com.box.sdkgen.networking.network.NetworkSession;
14
import com.box.sdkgen.schemas.fileversionfull.FileVersionFull;
15
import com.box.sdkgen.schemas.fileversions.FileVersions;
16
import com.box.sdkgen.serialization.json.JsonManager;
17
import java.util.Map;
18

19
public class FileVersionsManager {
20

21
  public Authentication auth;
22

23
  public NetworkSession networkSession;
24

25
  public FileVersionsManager() {
×
26
    this.networkSession = new NetworkSession();
×
27
  }
×
28

29
  protected FileVersionsManager(Builder builder) {
1✔
30
    this.auth = builder.auth;
1✔
31
    this.networkSession = builder.networkSession;
1✔
32
  }
1✔
33

34
  /**
35
   * Retrieve a list of the past versions for a file.
36
   *
37
   * <p>Versions are only tracked by Box users with premium accounts. To fetch the ID of the current
38
   * version of a file, use the `GET /file/:id` API.
39
   *
40
   * @param fileId The unique identifier that represents a file.
41
   *     <p>The ID for any file can be determined by visiting a file in the web application and
42
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
43
   *     `file_id` is `123`. Example: "12345"
44
   */
45
  public FileVersions getFileVersions(String fileId) {
46
    return getFileVersions(fileId, new GetFileVersionsQueryParams(), new GetFileVersionsHeaders());
1✔
47
  }
48

49
  /**
50
   * Retrieve a list of the past versions for a file.
51
   *
52
   * <p>Versions are only tracked by Box users with premium accounts. To fetch the ID of the current
53
   * version of a file, use the `GET /file/:id` API.
54
   *
55
   * @param fileId The unique identifier that represents a file.
56
   *     <p>The ID for any file can be determined by visiting a file in the web application and
57
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
58
   *     `file_id` is `123`. Example: "12345"
59
   * @param queryParams Query parameters of getFileVersions method
60
   */
61
  public FileVersions getFileVersions(String fileId, GetFileVersionsQueryParams queryParams) {
62
    return getFileVersions(fileId, queryParams, new GetFileVersionsHeaders());
×
63
  }
64

65
  /**
66
   * Retrieve a list of the past versions for a file.
67
   *
68
   * <p>Versions are only tracked by Box users with premium accounts. To fetch the ID of the current
69
   * version of a file, use the `GET /file/:id` API.
70
   *
71
   * @param fileId The unique identifier that represents a file.
72
   *     <p>The ID for any file can be determined by visiting a file in the web application and
73
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
74
   *     `file_id` is `123`. Example: "12345"
75
   * @param headers Headers of getFileVersions method
76
   */
77
  public FileVersions getFileVersions(String fileId, GetFileVersionsHeaders headers) {
78
    return getFileVersions(fileId, new GetFileVersionsQueryParams(), headers);
×
79
  }
80

81
  /**
82
   * Retrieve a list of the past versions for a file.
83
   *
84
   * <p>Versions are only tracked by Box users with premium accounts. To fetch the ID of the current
85
   * version of a file, use the `GET /file/:id` API.
86
   *
87
   * @param fileId The unique identifier that represents a file.
88
   *     <p>The ID for any file can be determined by visiting a file in the web application and
89
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
90
   *     `file_id` is `123`. Example: "12345"
91
   * @param queryParams Query parameters of getFileVersions method
92
   * @param headers Headers of getFileVersions method
93
   */
94
  public FileVersions getFileVersions(
95
      String fileId, GetFileVersionsQueryParams queryParams, GetFileVersionsHeaders headers) {
96
    Map<String, String> queryParamsMap =
1✔
97
        prepareParams(
1✔
98
            mapOf(
1✔
99
                entryOf("fields", convertToString(queryParams.getFields())),
1✔
100
                entryOf("limit", convertToString(queryParams.getLimit())),
1✔
101
                entryOf("offset", convertToString(queryParams.getOffset()))));
1✔
102
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
103
    FetchResponse response =
1✔
104
        this.networkSession
105
            .getNetworkClient()
1✔
106
            .fetch(
1✔
107
                new FetchOptions.Builder(
108
                        String.join(
1✔
109
                            "",
110
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
111
                            "/2.0/files/",
112
                            convertToString(fileId),
1✔
113
                            "/versions"),
114
                        "GET")
115
                    .params(queryParamsMap)
1✔
116
                    .headers(headersMap)
1✔
117
                    .responseFormat(ResponseFormat.JSON)
1✔
118
                    .auth(this.auth)
1✔
119
                    .networkSession(this.networkSession)
1✔
120
                    .build());
1✔
121
    return JsonManager.deserialize(response.getData(), FileVersions.class);
1✔
122
  }
123

124
  /**
125
   * Retrieve a specific version of a file.
126
   *
127
   * <p>Versions are only tracked for Box users with premium accounts.
128
   *
129
   * @param fileId The unique identifier that represents a file.
130
   *     <p>The ID for any file can be determined by visiting a file in the web application and
131
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
132
   *     `file_id` is `123`. Example: "12345"
133
   * @param fileVersionId The ID of the file version. Example: "1234"
134
   */
135
  public FileVersionFull getFileVersionById(String fileId, String fileVersionId) {
136
    return getFileVersionById(
1✔
137
        fileId,
138
        fileVersionId,
139
        new GetFileVersionByIdQueryParams(),
140
        new GetFileVersionByIdHeaders());
141
  }
142

143
  /**
144
   * Retrieve a specific version of a file.
145
   *
146
   * <p>Versions are only tracked for Box users with premium accounts.
147
   *
148
   * @param fileId The unique identifier that represents a file.
149
   *     <p>The ID for any file can be determined by visiting a file in the web application and
150
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
151
   *     `file_id` is `123`. Example: "12345"
152
   * @param fileVersionId The ID of the file version. Example: "1234"
153
   * @param queryParams Query parameters of getFileVersionById method
154
   */
155
  public FileVersionFull getFileVersionById(
156
      String fileId, String fileVersionId, GetFileVersionByIdQueryParams queryParams) {
157
    return getFileVersionById(fileId, fileVersionId, queryParams, new GetFileVersionByIdHeaders());
1✔
158
  }
159

160
  /**
161
   * Retrieve a specific version of a file.
162
   *
163
   * <p>Versions are only tracked for Box users with premium accounts.
164
   *
165
   * @param fileId The unique identifier that represents a file.
166
   *     <p>The ID for any file can be determined by visiting a file in the web application and
167
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
168
   *     `file_id` is `123`. Example: "12345"
169
   * @param fileVersionId The ID of the file version. Example: "1234"
170
   * @param headers Headers of getFileVersionById method
171
   */
172
  public FileVersionFull getFileVersionById(
173
      String fileId, String fileVersionId, GetFileVersionByIdHeaders headers) {
174
    return getFileVersionById(fileId, fileVersionId, new GetFileVersionByIdQueryParams(), headers);
×
175
  }
176

177
  /**
178
   * Retrieve a specific version of a file.
179
   *
180
   * <p>Versions are only tracked for Box users with premium accounts.
181
   *
182
   * @param fileId The unique identifier that represents a file.
183
   *     <p>The ID for any file can be determined by visiting a file in the web application and
184
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
185
   *     `file_id` is `123`. Example: "12345"
186
   * @param fileVersionId The ID of the file version. Example: "1234"
187
   * @param queryParams Query parameters of getFileVersionById method
188
   * @param headers Headers of getFileVersionById method
189
   */
190
  public FileVersionFull getFileVersionById(
191
      String fileId,
192
      String fileVersionId,
193
      GetFileVersionByIdQueryParams queryParams,
194
      GetFileVersionByIdHeaders headers) {
195
    Map<String, String> queryParamsMap =
1✔
196
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
197
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
198
    FetchResponse response =
1✔
199
        this.networkSession
200
            .getNetworkClient()
1✔
201
            .fetch(
1✔
202
                new FetchOptions.Builder(
203
                        String.join(
1✔
204
                            "",
205
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
206
                            "/2.0/files/",
207
                            convertToString(fileId),
1✔
208
                            "/versions/",
209
                            convertToString(fileVersionId)),
1✔
210
                        "GET")
211
                    .params(queryParamsMap)
1✔
212
                    .headers(headersMap)
1✔
213
                    .responseFormat(ResponseFormat.JSON)
1✔
214
                    .auth(this.auth)
1✔
215
                    .networkSession(this.networkSession)
1✔
216
                    .build());
1✔
217
    return JsonManager.deserialize(response.getData(), FileVersionFull.class);
1✔
218
  }
219

220
  /**
221
   * Move a file version to the trash.
222
   *
223
   * <p>Versions are only tracked for Box users with premium accounts.
224
   *
225
   * @param fileId The unique identifier that represents a file.
226
   *     <p>The ID for any file can be determined by visiting a file in the web application and
227
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
228
   *     `file_id` is `123`. Example: "12345"
229
   * @param fileVersionId The ID of the file version. Example: "1234"
230
   */
231
  public void deleteFileVersionById(String fileId, String fileVersionId) {
232
    deleteFileVersionById(fileId, fileVersionId, new DeleteFileVersionByIdHeaders());
1✔
233
  }
1✔
234

235
  /**
236
   * Move a file version to the trash.
237
   *
238
   * <p>Versions are only tracked for Box users with premium accounts.
239
   *
240
   * @param fileId The unique identifier that represents a file.
241
   *     <p>The ID for any file can be determined by visiting a file in the web application and
242
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
243
   *     `file_id` is `123`. Example: "12345"
244
   * @param fileVersionId The ID of the file version. Example: "1234"
245
   * @param headers Headers of deleteFileVersionById method
246
   */
247
  public void deleteFileVersionById(
248
      String fileId, String fileVersionId, DeleteFileVersionByIdHeaders headers) {
249
    Map<String, String> headersMap =
1✔
250
        prepareParams(
1✔
251
            mergeMaps(
1✔
252
                mapOf(entryOf("if-match", convertToString(headers.getIfMatch()))),
1✔
253
                headers.getExtraHeaders()));
1✔
254
    FetchResponse response =
1✔
255
        this.networkSession
256
            .getNetworkClient()
1✔
257
            .fetch(
1✔
258
                new FetchOptions.Builder(
259
                        String.join(
1✔
260
                            "",
261
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
262
                            "/2.0/files/",
263
                            convertToString(fileId),
1✔
264
                            "/versions/",
265
                            convertToString(fileVersionId)),
1✔
266
                        "DELETE")
267
                    .headers(headersMap)
1✔
268
                    .responseFormat(ResponseFormat.NO_CONTENT)
1✔
269
                    .auth(this.auth)
1✔
270
                    .networkSession(this.networkSession)
1✔
271
                    .build());
1✔
272
  }
1✔
273

274
  /**
275
   * Restores a specific version of a file after it was deleted. Don't use this endpoint to restore
276
   * Box Notes, as it works with file formats such as PDF, DOC, PPTX or similar.
277
   *
278
   * @param fileId The unique identifier that represents a file.
279
   *     <p>The ID for any file can be determined by visiting a file in the web application and
280
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
281
   *     `file_id` is `123`. Example: "12345"
282
   * @param fileVersionId The ID of the file version. Example: "1234"
283
   */
284
  public FileVersionFull updateFileVersionById(String fileId, String fileVersionId) {
285
    return updateFileVersionById(
×
286
        fileId,
287
        fileVersionId,
288
        new UpdateFileVersionByIdRequestBody(),
289
        new UpdateFileVersionByIdHeaders());
290
  }
291

292
  /**
293
   * Restores a specific version of a file after it was deleted. Don't use this endpoint to restore
294
   * Box Notes, as it works with file formats such as PDF, DOC, PPTX or similar.
295
   *
296
   * @param fileId The unique identifier that represents a file.
297
   *     <p>The ID for any file can be determined by visiting a file in the web application and
298
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
299
   *     `file_id` is `123`. Example: "12345"
300
   * @param fileVersionId The ID of the file version. Example: "1234"
301
   * @param requestBody Request body of updateFileVersionById method
302
   */
303
  public FileVersionFull updateFileVersionById(
304
      String fileId, String fileVersionId, UpdateFileVersionByIdRequestBody requestBody) {
305
    return updateFileVersionById(
1✔
306
        fileId, fileVersionId, requestBody, new UpdateFileVersionByIdHeaders());
307
  }
308

309
  /**
310
   * Restores a specific version of a file after it was deleted. Don't use this endpoint to restore
311
   * Box Notes, as it works with file formats such as PDF, DOC, PPTX or similar.
312
   *
313
   * @param fileId The unique identifier that represents a file.
314
   *     <p>The ID for any file can be determined by visiting a file in the web application and
315
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
316
   *     `file_id` is `123`. Example: "12345"
317
   * @param fileVersionId The ID of the file version. Example: "1234"
318
   * @param headers Headers of updateFileVersionById method
319
   */
320
  public FileVersionFull updateFileVersionById(
321
      String fileId, String fileVersionId, UpdateFileVersionByIdHeaders headers) {
322
    return updateFileVersionById(
×
323
        fileId, fileVersionId, new UpdateFileVersionByIdRequestBody(), headers);
324
  }
325

326
  /**
327
   * Restores a specific version of a file after it was deleted. Don't use this endpoint to restore
328
   * Box Notes, as it works with file formats such as PDF, DOC, PPTX or similar.
329
   *
330
   * @param fileId The unique identifier that represents a file.
331
   *     <p>The ID for any file can be determined by visiting a file in the web application and
332
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
333
   *     `file_id` is `123`. Example: "12345"
334
   * @param fileVersionId The ID of the file version. Example: "1234"
335
   * @param requestBody Request body of updateFileVersionById method
336
   * @param headers Headers of updateFileVersionById method
337
   */
338
  public FileVersionFull updateFileVersionById(
339
      String fileId,
340
      String fileVersionId,
341
      UpdateFileVersionByIdRequestBody requestBody,
342
      UpdateFileVersionByIdHeaders headers) {
343
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
344
    FetchResponse response =
1✔
345
        this.networkSession
346
            .getNetworkClient()
1✔
347
            .fetch(
1✔
348
                new FetchOptions.Builder(
349
                        String.join(
1✔
350
                            "",
351
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
352
                            "/2.0/files/",
353
                            convertToString(fileId),
1✔
354
                            "/versions/",
355
                            convertToString(fileVersionId)),
1✔
356
                        "PUT")
357
                    .headers(headersMap)
1✔
358
                    .data(JsonManager.serialize(requestBody))
1✔
359
                    .contentType("application/json")
1✔
360
                    .responseFormat(ResponseFormat.JSON)
1✔
361
                    .auth(this.auth)
1✔
362
                    .networkSession(this.networkSession)
1✔
363
                    .build());
1✔
364
    return JsonManager.deserialize(response.getData(), FileVersionFull.class);
1✔
365
  }
366

367
  /**
368
   * Promote a specific version of a file.
369
   *
370
   * <p>If previous versions exist, this method can be used to promote one of the older versions to
371
   * the top of the version history.
372
   *
373
   * <p>This creates a new copy of the old version and puts it at the top of the versions history.
374
   * The file will have the exact same contents as the older version, with the same hash digest,
375
   * `etag`, and name as the original.
376
   *
377
   * <p>Other properties such as comments do not get updated to their former values.
378
   *
379
   * <p>Don't use this endpoint to restore Box Notes, as it works with file formats such as PDF,
380
   * DOC, PPTX or similar.
381
   *
382
   * @param fileId The unique identifier that represents a file.
383
   *     <p>The ID for any file can be determined by visiting a file in the web application and
384
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
385
   *     `file_id` is `123`. Example: "12345"
386
   */
387
  public FileVersionFull promoteFileVersion(String fileId) {
388
    return promoteFileVersion(
×
389
        fileId,
390
        new PromoteFileVersionRequestBody(),
391
        new PromoteFileVersionQueryParams(),
392
        new PromoteFileVersionHeaders());
393
  }
394

395
  /**
396
   * Promote a specific version of a file.
397
   *
398
   * <p>If previous versions exist, this method can be used to promote one of the older versions to
399
   * the top of the version history.
400
   *
401
   * <p>This creates a new copy of the old version and puts it at the top of the versions history.
402
   * The file will have the exact same contents as the older version, with the same hash digest,
403
   * `etag`, and name as the original.
404
   *
405
   * <p>Other properties such as comments do not get updated to their former values.
406
   *
407
   * <p>Don't use this endpoint to restore Box Notes, as it works with file formats such as PDF,
408
   * DOC, PPTX or similar.
409
   *
410
   * @param fileId The unique identifier that represents a file.
411
   *     <p>The ID for any file can be determined by visiting a file in the web application and
412
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
413
   *     `file_id` is `123`. Example: "12345"
414
   * @param requestBody Request body of promoteFileVersion method
415
   */
416
  public FileVersionFull promoteFileVersion(
417
      String fileId, PromoteFileVersionRequestBody requestBody) {
418
    return promoteFileVersion(
1✔
419
        fileId, requestBody, new PromoteFileVersionQueryParams(), new PromoteFileVersionHeaders());
420
  }
421

422
  /**
423
   * Promote a specific version of a file.
424
   *
425
   * <p>If previous versions exist, this method can be used to promote one of the older versions to
426
   * the top of the version history.
427
   *
428
   * <p>This creates a new copy of the old version and puts it at the top of the versions history.
429
   * The file will have the exact same contents as the older version, with the same hash digest,
430
   * `etag`, and name as the original.
431
   *
432
   * <p>Other properties such as comments do not get updated to their former values.
433
   *
434
   * <p>Don't use this endpoint to restore Box Notes, as it works with file formats such as PDF,
435
   * DOC, PPTX or similar.
436
   *
437
   * @param fileId The unique identifier that represents a file.
438
   *     <p>The ID for any file can be determined by visiting a file in the web application and
439
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
440
   *     `file_id` is `123`. Example: "12345"
441
   * @param queryParams Query parameters of promoteFileVersion method
442
   */
443
  public FileVersionFull promoteFileVersion(
444
      String fileId, PromoteFileVersionQueryParams queryParams) {
445
    return promoteFileVersion(
×
446
        fileId, new PromoteFileVersionRequestBody(), queryParams, new PromoteFileVersionHeaders());
447
  }
448

449
  /**
450
   * Promote a specific version of a file.
451
   *
452
   * <p>If previous versions exist, this method can be used to promote one of the older versions to
453
   * the top of the version history.
454
   *
455
   * <p>This creates a new copy of the old version and puts it at the top of the versions history.
456
   * The file will have the exact same contents as the older version, with the same hash digest,
457
   * `etag`, and name as the original.
458
   *
459
   * <p>Other properties such as comments do not get updated to their former values.
460
   *
461
   * <p>Don't use this endpoint to restore Box Notes, as it works with file formats such as PDF,
462
   * DOC, PPTX or similar.
463
   *
464
   * @param fileId The unique identifier that represents a file.
465
   *     <p>The ID for any file can be determined by visiting a file in the web application and
466
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
467
   *     `file_id` is `123`. Example: "12345"
468
   * @param requestBody Request body of promoteFileVersion method
469
   * @param queryParams Query parameters of promoteFileVersion method
470
   */
471
  public FileVersionFull promoteFileVersion(
472
      String fileId,
473
      PromoteFileVersionRequestBody requestBody,
474
      PromoteFileVersionQueryParams queryParams) {
475
    return promoteFileVersion(fileId, requestBody, queryParams, new PromoteFileVersionHeaders());
×
476
  }
477

478
  /**
479
   * Promote a specific version of a file.
480
   *
481
   * <p>If previous versions exist, this method can be used to promote one of the older versions to
482
   * the top of the version history.
483
   *
484
   * <p>This creates a new copy of the old version and puts it at the top of the versions history.
485
   * The file will have the exact same contents as the older version, with the same hash digest,
486
   * `etag`, and name as the original.
487
   *
488
   * <p>Other properties such as comments do not get updated to their former values.
489
   *
490
   * <p>Don't use this endpoint to restore Box Notes, as it works with file formats such as PDF,
491
   * DOC, PPTX or similar.
492
   *
493
   * @param fileId The unique identifier that represents a file.
494
   *     <p>The ID for any file can be determined by visiting a file in the web application and
495
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
496
   *     `file_id` is `123`. Example: "12345"
497
   * @param headers Headers of promoteFileVersion method
498
   */
499
  public FileVersionFull promoteFileVersion(String fileId, PromoteFileVersionHeaders headers) {
500
    return promoteFileVersion(
×
501
        fileId, new PromoteFileVersionRequestBody(), new PromoteFileVersionQueryParams(), headers);
502
  }
503

504
  /**
505
   * Promote a specific version of a file.
506
   *
507
   * <p>If previous versions exist, this method can be used to promote one of the older versions to
508
   * the top of the version history.
509
   *
510
   * <p>This creates a new copy of the old version and puts it at the top of the versions history.
511
   * The file will have the exact same contents as the older version, with the same hash digest,
512
   * `etag`, and name as the original.
513
   *
514
   * <p>Other properties such as comments do not get updated to their former values.
515
   *
516
   * <p>Don't use this endpoint to restore Box Notes, as it works with file formats such as PDF,
517
   * DOC, PPTX or similar.
518
   *
519
   * @param fileId The unique identifier that represents a file.
520
   *     <p>The ID for any file can be determined by visiting a file in the web application and
521
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
522
   *     `file_id` is `123`. Example: "12345"
523
   * @param requestBody Request body of promoteFileVersion method
524
   * @param headers Headers of promoteFileVersion method
525
   */
526
  public FileVersionFull promoteFileVersion(
527
      String fileId, PromoteFileVersionRequestBody requestBody, PromoteFileVersionHeaders headers) {
528
    return promoteFileVersion(fileId, requestBody, new PromoteFileVersionQueryParams(), headers);
×
529
  }
530

531
  /**
532
   * Promote a specific version of a file.
533
   *
534
   * <p>If previous versions exist, this method can be used to promote one of the older versions to
535
   * the top of the version history.
536
   *
537
   * <p>This creates a new copy of the old version and puts it at the top of the versions history.
538
   * The file will have the exact same contents as the older version, with the same hash digest,
539
   * `etag`, and name as the original.
540
   *
541
   * <p>Other properties such as comments do not get updated to their former values.
542
   *
543
   * <p>Don't use this endpoint to restore Box Notes, as it works with file formats such as PDF,
544
   * DOC, PPTX or similar.
545
   *
546
   * @param fileId The unique identifier that represents a file.
547
   *     <p>The ID for any file can be determined by visiting a file in the web application and
548
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
549
   *     `file_id` is `123`. Example: "12345"
550
   * @param queryParams Query parameters of promoteFileVersion method
551
   * @param headers Headers of promoteFileVersion method
552
   */
553
  public FileVersionFull promoteFileVersion(
554
      String fileId, PromoteFileVersionQueryParams queryParams, PromoteFileVersionHeaders headers) {
555
    return promoteFileVersion(fileId, new PromoteFileVersionRequestBody(), queryParams, headers);
×
556
  }
557

558
  /**
559
   * Promote a specific version of a file.
560
   *
561
   * <p>If previous versions exist, this method can be used to promote one of the older versions to
562
   * the top of the version history.
563
   *
564
   * <p>This creates a new copy of the old version and puts it at the top of the versions history.
565
   * The file will have the exact same contents as the older version, with the same hash digest,
566
   * `etag`, and name as the original.
567
   *
568
   * <p>Other properties such as comments do not get updated to their former values.
569
   *
570
   * <p>Don't use this endpoint to restore Box Notes, as it works with file formats such as PDF,
571
   * DOC, PPTX or similar.
572
   *
573
   * @param fileId The unique identifier that represents a file.
574
   *     <p>The ID for any file can be determined by visiting a file in the web application and
575
   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
576
   *     `file_id` is `123`. Example: "12345"
577
   * @param requestBody Request body of promoteFileVersion method
578
   * @param queryParams Query parameters of promoteFileVersion method
579
   * @param headers Headers of promoteFileVersion method
580
   */
581
  public FileVersionFull promoteFileVersion(
582
      String fileId,
583
      PromoteFileVersionRequestBody requestBody,
584
      PromoteFileVersionQueryParams queryParams,
585
      PromoteFileVersionHeaders headers) {
586
    Map<String, String> queryParamsMap =
1✔
587
        prepareParams(mapOf(entryOf("fields", convertToString(queryParams.getFields()))));
1✔
588
    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
1✔
589
    FetchResponse response =
1✔
590
        this.networkSession
591
            .getNetworkClient()
1✔
592
            .fetch(
1✔
593
                new FetchOptions.Builder(
594
                        String.join(
1✔
595
                            "",
596
                            this.networkSession.getBaseUrls().getBaseUrl(),
1✔
597
                            "/2.0/files/",
598
                            convertToString(fileId),
1✔
599
                            "/versions/current"),
600
                        "POST")
601
                    .params(queryParamsMap)
1✔
602
                    .headers(headersMap)
1✔
603
                    .data(JsonManager.serialize(requestBody))
1✔
604
                    .contentType("application/json")
1✔
605
                    .responseFormat(ResponseFormat.JSON)
1✔
606
                    .auth(this.auth)
1✔
607
                    .networkSession(this.networkSession)
1✔
608
                    .build());
1✔
609
    return JsonManager.deserialize(response.getData(), FileVersionFull.class);
1✔
610
  }
611

612
  public Authentication getAuth() {
613
    return auth;
×
614
  }
615

616
  public NetworkSession getNetworkSession() {
617
    return networkSession;
×
618
  }
619

620
  public static class Builder {
621

622
    protected Authentication auth;
623

624
    protected NetworkSession networkSession;
625

626
    public Builder() {
1✔
627
      this.networkSession = new NetworkSession();
1✔
628
    }
1✔
629

630
    public Builder auth(Authentication auth) {
631
      this.auth = auth;
1✔
632
      return this;
1✔
633
    }
634

635
    public Builder networkSession(NetworkSession networkSession) {
636
      this.networkSession = networkSession;
1✔
637
      return this;
1✔
638
    }
639

640
    public FileVersionsManager build() {
641
      return new FileVersionsManager(this);
1✔
642
    }
643
  }
644
}
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