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

smartsheet / smartsheet-java-sdk / #67

09 Jul 2026 02:57PM UTC coverage: 59.797% (-0.2%) from 59.997%
#67

push

github

web-flow
Merge pull request #183 from smartsheet/release/4.2.0

Prepare for release v4.2.0

4532 of 7579 relevant lines covered (59.8%)

0.6 hits per line

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

30.77
/src/main/java/com/smartsheet/api/internal/ReportResourcesImpl.java
1
/*
2
 * Copyright (C) 2025 Smartsheet
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.smartsheet.api.internal;
18

19
import com.smartsheet.api.AuthorizationException;
20
import com.smartsheet.api.InvalidRequestException;
21
import com.smartsheet.api.ReportResources;
22
import com.smartsheet.api.ResourceNotFoundException;
23
import com.smartsheet.api.ServiceUnavailableException;
24
import com.smartsheet.api.SmartsheetException;
25
import com.smartsheet.api.internal.http.HttpEntity;
26
import com.smartsheet.api.internal.http.HttpMethod;
27
import com.smartsheet.api.internal.http.HttpRequest;
28
import com.smartsheet.api.internal.http.HttpResponse;
29
import com.smartsheet.api.internal.json.JSONSerializerException;
30
import com.smartsheet.api.internal.util.QueryUtil;
31
import com.smartsheet.api.models.CreateReportRequest;
32
import com.smartsheet.api.models.CreateReportResult;
33
import com.smartsheet.api.models.PagedResult;
34
import com.smartsheet.api.models.PaginationParameters;
35
import com.smartsheet.api.models.Report;
36
import com.smartsheet.api.models.ReportColumn;
37
import com.smartsheet.api.models.ReportDefinition;
38
import com.smartsheet.api.models.ReportPublish;
39
import com.smartsheet.api.models.Result;
40
import com.smartsheet.api.models.ReportScopeInclusion;
41
import com.smartsheet.api.models.SheetEmail;
42
import com.smartsheet.api.models.ReportPathNode;
43
import com.smartsheet.api.models.TokenPaginatedResult;
44
import com.smartsheet.api.models.UpdateReportColumnRequest;
45
import com.smartsheet.api.internal.util.Util;
46
import com.smartsheet.api.models.enums.ReportInclusion;
47

48
import java.io.ByteArrayInputStream;
49
import java.io.ByteArrayOutputStream;
50
import java.io.OutputStream;
51
import java.text.SimpleDateFormat;
52
import java.util.Date;
53
import java.util.EnumSet;
54
import java.util.HashMap;
55
import java.util.Map;
56
import java.util.List;
57

58
/**
59
 * This is the implementation of the ReportResources.
60
 * <p>
61
 * Thread Safety: This class is thread safe because it is immutable and its base class is thread safe.
62
 */
63

64
public class ReportResourcesImpl extends AbstractResources implements ReportResources {
65

66
    private static final String JSON_CONTENT_TYPE = "application/json";
67
    private static final String REPORTS_PATH = "reports/";
68
    private static final String REPORTS = "reports";
69
    private static final String SCOPE_PATH = "/scope";
70
    private static final String COLUMNS_PATH = "/columns/";
71

72
    /**
73
     * Constructor.
74
     * <p>
75
     * Parameters: - smartsheet : the SmartsheetImpl
76
     * <p>
77
     * Exceptions: - IllegalArgumentException : if any argument is null
78
     *
79
     * @param smartsheet the smartsheet
80
     */
81
    public ReportResourcesImpl(SmartsheetImpl smartsheet) {
82
        super(smartsheet);
1✔
83
    }
1✔
84

85
    /**
86
     * Get a report.
87
     * <p>
88
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id}
89
     * <p>
90
     * Exceptions:
91
     * InvalidRequestException : if there is any problem with the REST API request
92
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
93
     * ResourceNotFoundException : if the resource can not be found
94
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
95
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
96
     * SmartsheetException : if there is any other error occurred during the operation
97
     *
98
     * @param reportId the folder id
99
     * @param includes the optional objects to include in response
100
     * @param pageSize Number of rows per page
101
     * @param page     page number to return
102
     * @return the report (note that if there is no such resource, this method will throw ResourceNotFoundException
103
     * rather than returning null)
104
     * @throws SmartsheetException the smartsheet exception
105
     */
106
    public Report getReport(long reportId, EnumSet<ReportInclusion> includes, Integer pageSize, Integer page) throws SmartsheetException {
107
        return this.getReport(reportId, includes, pageSize, page, null);
1✔
108
    }
109

110
    /**
111
     * Get a report.
112
     * <p>
113
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id}
114
     * <p>
115
     * Exceptions:
116
     * InvalidRequestException : if there is any problem with the REST API request
117
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
118
     * ResourceNotFoundException : if the resource can not be found
119
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
120
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
121
     * SmartsheetException : if there is any other error occurred during the operation
122
     *
123
     * @param reportId the folder id
124
     * @param includes the optional objects to include in response
125
     * @param pageSize Number of rows per page
126
     * @param page     page number to return
127
     * @param level    compatibility level
128
     * @return the report (note that if there is no such resource, this method will throw ResourceNotFoundException
129
     * rather than returning null)
130
     * @throws SmartsheetException the smartsheet exception
131
     */
132
    public Report getReport(
133
            long reportId,
134
            EnumSet<ReportInclusion> includes,
135
            Integer pageSize,
136
            Integer page,
137
            Integer level
138
    ) throws SmartsheetException {
139
        String path = REPORTS_PATH + reportId;
1✔
140
        Map<String, Object> parameters = new HashMap<>();
1✔
141

142
        parameters.put("include", QueryUtil.generateCommaSeparatedList(includes));
1✔
143
        if (pageSize != null) {
1✔
144
            parameters.put("pageSize", pageSize.toString());
1✔
145
        }
146

147
        if (page != null) {
1✔
148
            parameters.put("page", page.toString());
1✔
149
        }
150

151
        if (level != null) {
1✔
152
            parameters.put("level", level);
×
153
        }
154

155
        path += QueryUtil.generateUrl(null, parameters);
1✔
156
        return this.getResource(path, Report.class);
1✔
157
    }
158

159
    /**
160
     * Sends a report as a PDF attachment via email to the designated recipients.
161
     * <p>
162
     * It mirrors to the following Smartsheet REST API method: POST /reports/{id}/emails
163
     * <p>
164
     * Exceptions:
165
     * InvalidRequestException : if there is any problem with the REST API request
166
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
167
     * ResourceNotFoundException : if the resource can not be found
168
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
169
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
170
     * SmartsheetException : if there is any other error occurred during the operation
171
     *
172
     * @param reportId the report id
173
     * @param email    the recipient email
174
     * @throws SmartsheetException the smartsheet exception
175
     */
176
    public void sendReport(long reportId, SheetEmail email) throws SmartsheetException {
177
        this.createResource(REPORTS_PATH + reportId + "/emails", SheetEmail.class, email);
1✔
178
    }
1✔
179

180
    /**
181
     * List all reports.
182
     * <p>
183
     * It mirrors to the following Smartsheet REST API method: GET /reports
184
     * <p>
185
     * Exceptions:
186
     * - InvalidRequestException : if there is any problem with the REST API request
187
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
188
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
189
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
190
     * - SmartsheetException : if there is any other error occurred during the operation
191
     *
192
     * @param pagination pagination parameters for paging result
193
     * @return all sheets (note that empty list will be returned if there is none)
194
     * @throws SmartsheetException the smartsheet exception
195
     */
196
    public PagedResult<Report> listReports(PaginationParameters pagination) throws SmartsheetException {
197
        return this.listReports(pagination, null);
×
198
    }
199

200
    /**
201
     * List all reports.
202
     */
203
    public PagedResult<Report> listReports(PaginationParameters pagination, Date modifiedSince) throws SmartsheetException {
204
        String path = REPORTS;
1✔
205

206
        Map<String, Object> parameters = new HashMap<>();
1✔
207
        if (pagination != null) {
1✔
208
            parameters = pagination.toHashMap();
1✔
209
        }
210
        if (modifiedSince != null) {
1✔
211
            String isoDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(modifiedSince);
×
212
            parameters.put("modifiedSince", isoDate);
×
213
        }
214

215
        path += QueryUtil.generateUrl(null, parameters);
1✔
216
        return this.listResourcesWithWrapper(path, Report.class);
1✔
217
    }
218

219
    /**
220
     * Get a Report as an Excel file.
221
     * <p>
222
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id} with "application/vnd.ms-excel" Accept
223
     * HTTP header
224
     * <p>
225
     * Exceptions:
226
     * IllegalArgumentException : if outputStream is null
227
     * InvalidRequestException : if there is any problem with the REST API request
228
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
229
     * ResourceNotFoundException : if the resource can not be found
230
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
231
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
232
     * SmartsheetException : if there is any other error occurred during the operation
233
     *
234
     * @param id           the id
235
     * @param outputStream the OutputStream to which the Excel file will be written
236
     * @throws SmartsheetException the smartsheet exception
237
     */
238
    public void getReportAsExcel(long id, OutputStream outputStream) throws SmartsheetException {
239
        getResourceAsFile(REPORTS_PATH + id, "application/vnd.ms-excel", outputStream);
1✔
240
    }
1✔
241

242
    /**
243
     * Get a Report as a csv file.
244
     * <p>
245
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id} with "text/csv" Accept
246
     * HTTP header
247
     * <p>
248
     * Exceptions:
249
     * IllegalArgumentException : if outputStream is null
250
     * InvalidRequestException : if there is any problem with the REST API request
251
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
252
     * ResourceNotFoundException : if the resource can not be found
253
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
254
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
255
     * SmartsheetException : if there is any other error occurred during the operation
256
     *
257
     * @param id           the id
258
     * @param outputStream the OutputStream to which the Excel file will be written
259
     * @throws SmartsheetException the smartsheet exception
260
     */
261
    public void getReportAsCsv(long id, OutputStream outputStream) throws SmartsheetException {
262
        getResourceAsFile(REPORTS_PATH + id, "text/csv", outputStream);
×
263
    }
×
264

265
    /**
266
     * Get the publish status of a report.
267
     * <p>
268
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id}/publish
269
     * <p>
270
     * Exceptions:
271
     * InvalidRequestException : if there is any problem with the REST API request
272
     * AuthorizationException : if there is any problem with the REST API authorization(access token)
273
     * ResourceNotFoundException : if the resource can not be found
274
     * ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
275
     * SmartsheetRestException : if there is any other REST API related error occurred during the operation
276
     * SmartsheetException : if there is any other error occurred during the operation
277
     *
278
     * @param id the ID of the report
279
     * @return the report publish status (note that if there is no such resource, this method will
280
     * throw ResourceNotFoundException rather than returning null).
281
     * @throws IllegalArgumentException    if any argument is null or empty string
282
     * @throws InvalidRequestException     if there is any problem with the REST API request
283
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
284
     * @throws ResourceNotFoundException   if the resource cannot be found
285
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
286
     * @throws SmartsheetException         if there is any other error during the operation
287
     */
288
    public ReportPublish getPublishStatus(long id) throws SmartsheetException {
289
        return this.getResource(REPORTS_PATH + id + "/publish", ReportPublish.class);
×
290
    }
291

292
    /**
293
     * Sets the publish status of a report and returns the new status, including the URLs of any
294
     * enabled publishing.
295
     * <p>
296
     * It mirrors to the following Smartsheet REST API method: PUT /reports/{id}/publish
297
     * <p>
298
     * Exceptions:
299
     * - InvalidRequestException : if there is any problem with the REST API request
300
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
301
     * - ResourceNotFoundException : if the resource can not be found
302
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
303
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
304
     * - SmartsheetException : if there is any other error occurred during the operation
305
     *
306
     * @param id            the ID of the report
307
     * @param reportPublish the ReportPublish object
308
     * @return the updated ReportPublish (note that if there is no such resource, this method will
309
     * throw ResourceNotFoundException rather than returning null)
310
     * @throws IllegalArgumentException    if any argument is null or empty string
311
     * @throws InvalidRequestException     if there is any problem with the REST API request
312
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
313
     * @throws ResourceNotFoundException   if the resource cannot be found
314
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
315
     * @throws SmartsheetException         if there is any other error during the operation
316
     */
317
    public ReportPublish updatePublishStatus(long id, ReportPublish reportPublish) throws SmartsheetException {
318
        return this.updateResource(REPORTS_PATH + id + "/publish", ReportPublish.class, reportPublish);
×
319
    }
320

321
    /**
322
     * Gets a report's definition (filters, grouping, summarizing, and sorting).
323
     * <p>
324
     * It mirrors to the following Smartsheet REST API method: GET /reports/{id}/definition
325
     *
326
     * @param reportId the ID of the report
327
     * @return the ReportDefinition object
328
     * @throws SmartsheetException the smartsheet exception
329
     */
330
    @Override
331
    public ReportDefinition getReportDefinition(long reportId) throws SmartsheetException {
332
        return this.getResource(REPORTS_PATH + reportId + "/definition", ReportDefinition.class);
×
333
    }
334

335
    /**
336
     * Updates a report's definition (filters, grouping, summarizing, and sorting).
337
     * <p>
338
     * It mirrors to the following Smartsheet REST API method: PUT /reports/{id}/definition
339
     * <p>
340
     * This endpoint supports partial updates only on root level properties of the report definition,
341
     * such as filters, groupingCriteria, and summarizingCriteria. For example, you can update the
342
     * report's filters without affecting its grouping criteria. However, nested properties within
343
     * these objects, such as a specific filter or grouping criterion, cannot be updated individually
344
     * and require a full replacement of the respective section.
345
     * <p>
346
     * Exceptions:
347
     * - InvalidRequestException : if there is any problem with the REST API request
348
     * - AuthorizationException : if there is any problem with the REST API authorization(access token)
349
     * - ResourceNotFoundException : if the resource can not be found
350
     * - ServiceUnavailableException : if the REST API service is not available (possibly due to rate limiting)
351
     * - SmartsheetRestException : if there is any other REST API related error occurred during the operation
352
     * - SmartsheetException : if there is any other error occurred during the operation
353
     *
354
     * @param id         the ID of the report
355
     * @param reportDefinition the ReportDefinition object containing the updated definition
356
     * @throws IllegalArgumentException    if any argument is null
357
     * @throws InvalidRequestException     if there is any problem with the REST API request
358
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
359
     * @throws ResourceNotFoundException   if the resource cannot be found
360
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
361
     * @throws SmartsheetException         if there is any other error during the operation
362
     */
363
    public void updateReportDefinition(long id, ReportDefinition reportDefinition) throws SmartsheetException {
364
        String path = REPORTS_PATH + id + "/definition";
×
365
        this.putResource(path, Result.class, reportDefinition);
×
366
    }
×
367

368
    /**
369
     * <p>Deletes a report.</p>
370
     *
371
     * <p>Mirrors the following Smartsheet REST API method: DELETE /reports/{reportId}</p>
372
     *
373
     * @param id the id of the report
374
     * @throws IllegalArgumentException    if any argument is null or empty string
375
     * @throws InvalidRequestException     if there is any problem with the REST API request
376
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
377
     * @throws ResourceNotFoundException   if the resource cannot be found
378
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
379
     * @throws SmartsheetException         if there is any other error during the operation
380
     */
381
    public void deleteReport(long id) throws SmartsheetException {
382
        this.deleteResource(REPORTS_PATH + id, Report.class);
1✔
383
    }
1✔
384

385
    /**
386
     * <p>Adds one or more specified sheet or workspace to the report scope.</p>
387
     *
388
     * @param id          the ID of the report
389
     * @param scopes A list of one or more objects denoting the sheets or workspaces associated with
390
     *               the report to be added to the report scope.
391
     * @throws IllegalArgumentException    if any argument is null or empty
392
     * @throws InvalidRequestException     if there is any problem with the REST API request
393
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
394
     * @throws ResourceNotFoundException   if the resource cannot be found
395
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
396
     * @throws SmartsheetException         if there is any other error during the operation
397
     */
398
    @Override
399
    public void addReportScope(long id, List<ReportScopeInclusion> scopes) throws SmartsheetException {
400
        Util.throwIfNull(scopes);
×
401

402
        if (scopes.isEmpty()) {
×
403
            throw new IllegalArgumentException("scopes should not be empty.");
×
404
        }
405

406
        String path = REPORTS_PATH + id + SCOPE_PATH;
×
407
        HttpRequest request = createHttpRequest(smartsheet.getBaseURI().resolve(path), HttpMethod.POST);
×
408
        setRequestEntity(request, scopes);
×
409

410
        try {
411
            HttpResponse response = this.smartsheet.getHttpClient().request(request);
×
412
            if (response.getStatusCode() != 200) {
×
413
                handleError(response);
×
414
            }
415
        } finally {
416
            smartsheet.getHttpClient().releaseConnection();
×
417
        }
418
    }
×
419

420
    /**
421
     * <p>Removes one or more specified sheet or workspace from the report scope.</p>
422
     *
423
     * @param id             the ID of the report
424
     * @param scopes A list of one or more objects denoting the sheets or workspaces associated with
425
     *               the report to be removed from the report scope.
426
     * @throws IllegalArgumentException    if any argument is null or empty
427
     * @throws InvalidRequestException     if there is any problem with the REST API request
428
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
429
     * @throws ResourceNotFoundException   if the resource cannot be found
430
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
431
     * @throws SmartsheetException         if there is any other error during the operation
432
     */
433
    @Override
434
    public void removeReportScope(long id, List<ReportScopeInclusion> scopes) throws SmartsheetException {
435
        Util.throwIfNull(scopes);
×
436

437
        if (scopes.isEmpty()) {
×
438
            throw new IllegalArgumentException("scopes should not be empty.");
×
439
        }
440

441
        String path = REPORTS_PATH + id + SCOPE_PATH;
×
442
        HttpRequest request = createHttpRequest(smartsheet.getBaseURI().resolve(path), HttpMethod.DELETE);
×
443
        setRequestEntity(request, scopes);
×
444

445
        try {
446
            HttpResponse response = this.smartsheet.getHttpClient().request(request);
×
447
            if (response.getStatusCode() != 200) {
×
448
                handleError(response);
×
449
            }
450
        } finally {
451
            smartsheet.getHttpClient().releaseConnection();
×
452
        }
453
    }
×
454

455
    /**
456
     * <p>Add reportColumns to a report.</p>
457
     *
458
     * <p>It mirrors to the following Smartsheet REST API method: POST /reports/{reportId}/reportColumns</p>
459
     *
460
     * <p>Note: All indexes of the reportColumns must be equal.</p>
461
     *
462
     * @param reportId the ID of the report
463
     * @param reportColumns  the list of reportColumns to add (must contain 1-400 items)
464
     * @return the list of reportColumns that were added
465
     * @throws IllegalArgumentException    if any argument is null or empty
466
     * @throws InvalidRequestException     if there is any problem with the REST API request
467
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
468
     * @throws ResourceNotFoundException   if the resource cannot be found
469
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
470
     * @throws SmartsheetException         if there is any other error during the operation
471
     */
472
    @Override
473
    public List<ReportColumn> addReportColumns(long reportId, List<ReportColumn> reportColumns) throws SmartsheetException {
474
        Util.throwIfNull(reportColumns);
1✔
475

476
        if (reportColumns.isEmpty()) {
1✔
477
            throw new IllegalArgumentException("reportColumns should not be empty.");
×
478
        }
479

480
        return this.postAndReceiveList(REPORTS_PATH + reportId + "/columns", reportColumns, ReportColumn.class);
1✔
481
    }
482

483
    /**
484
     * <p>List columns for a report.</p>
485
     *
486
     * <p>It mirrors to the following Smartsheet REST API method: GET /reports/{reportId}/columns</p>
487
     *
488
     * @param reportId the ID of the report
489
     * @param lastKey  token for retrieving the next page of results (optional)
490
     * @param maxItems maximum number of items to return (optional)
491
     * @return a TokenPaginatedResult containing the list of ReportColumn objects and a lastKey for pagination
492
     * @throws IllegalArgumentException    if any argument is null or empty string
493
     * @throws InvalidRequestException     if there is any problem with the REST API request
494
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
495
     * @throws ResourceNotFoundException   if the resource cannot be found
496
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
497
     * @throws SmartsheetException         if there is any other error during the operation
498
     */
499
    @Override
500
    public TokenPaginatedResult<ReportColumn> listReportColumns(long reportId, String lastKey, Long maxItems) throws SmartsheetException {
501
        return listReportColumns(reportId, lastKey, maxItems, null);
×
502
    }
503

504
    /**
505
     * <p>List columns for a report.</p>
506
     *
507
     * <p>It mirrors to the following Smartsheet REST API method: GET /reports/{reportId}/columns</p>
508
     *
509
     * @param reportId the ID of the report
510
     * @param lastKey  token for retrieving the next page of results (optional)
511
     * @param maxItems maximum number of items to return (optional)
512
     * @param level compatibility level
513
     * @return a TokenPaginatedResult containing the list of ReportColumn objects and a lastKey for pagination
514
     * @throws SmartsheetException if there is any error during the operation
515
     */
516
    @Override
517
    public TokenPaginatedResult<ReportColumn> listReportColumns(long reportId, String lastKey, Long maxItems, Integer level) throws SmartsheetException {
518
        String path = REPORTS_PATH + reportId + "/columns";
×
519
        Map<String, Object> parameters = new HashMap<>();
×
520
        if (lastKey != null) {
×
521
            parameters.put("lastKey", lastKey);
×
522
        }
523
        if (maxItems != null) {
×
524
            parameters.put("maxItems", maxItems);
×
525
        }
526
        if (level != null) {
×
527
            parameters.put("level", level);
×
528
        }
529
        path += QueryUtil.generateUrl(null, parameters);
×
530
        return listResourcesWithTokenPagination(path, ReportColumn.class);
×
531
    }
532

533
    /**
534
     * <p>List the scope of a report (the sheets and workspaces included in the report).</p>
535
     *
536
     * <p>It mirrors to the following Smartsheet REST API method: GET /reports/{reportId}/scope</p>
537
     *
538
     * @param reportId the ID of the report
539
     * @param lastKey  token for retrieving the next page of results (optional)
540
     * @param maxItems maximum number of items to return (optional)
541
     * @return a TokenPaginatedResult containing the list of ReportScopeInclusion objects
542
     * @throws SmartsheetException if there is any error during the operation
543
     */
544
    @Override
545
    public TokenPaginatedResult<ReportScopeInclusion> listReportScope(
546
            long reportId, String lastKey, Long maxItems) throws SmartsheetException {
547
        String path = REPORTS_PATH + reportId + SCOPE_PATH;
×
548
        Map<String, Object> parameters = new HashMap<>();
×
549
        if (lastKey != null) {
×
550
            parameters.put("lastKey", lastKey);
×
551
        }
552
        if (maxItems != null) {
×
553
            parameters.put("maxItems", maxItems);
×
554
        }
555
        path += QueryUtil.generateUrl(null, parameters);
×
556
        return listResourcesWithTokenPagination(path, ReportScopeInclusion.class);
×
557
    }
558

559
    /**
560
     * <p>Create a new report.</p>
561
     *
562
     * <p>It mirrors to the following Smartsheet REST API method: POST /reports</p>
563
     *
564
     * <p>Creates a new report by specifying name, destination, scope, columns and definition.</p>
565
     *
566
     * @param request the CreateReportRequest containing report specifications
567
     * @return the CreateReportResult containing the newly created report information
568
     * @throws IllegalArgumentException    if any argument is null
569
     * @throws InvalidRequestException     if there is any problem with the REST API request
570
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
571
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
572
     * @throws SmartsheetException         if there is any other error during the operation
573
     */
574
    @Override
575
    public CreateReportResult createReport(CreateReportRequest request) throws SmartsheetException {
576
        Util.throwIfNull(request);
1✔
577

578
        return this.createResource(REPORTS, CreateReportResult.class, request);
1✔
579
    }
580

581
    /**
582
     * Get the path of a report (workspace/folder hierarchy).
583
     * <p>
584
     * It mirrors to the following Smartsheet REST API method: GET /reports/{reportId}/path
585
     *
586
     * @param reportId the report id
587
     * @return the container path
588
     * @throws SmartsheetException the smartsheet exception
589
     */
590
    @Override
591
    public ReportPathNode getReportPath(long reportId) throws SmartsheetException {
592
        return this.getResource(REPORTS_PATH + reportId + "/path", ReportPathNode.class);
1✔
593
    }
594

595
    /**
596
     * Get a single column from a report.
597
     * <p>
598
     * It mirrors to the following Smartsheet REST API method: GET /reports/{reportId}/columns/{columnVirtualId}
599
     *
600
     * @param reportId        the ID of the report
601
     * @param columnVirtualId the virtual ID of the column
602
     * @return the ReportColumn
603
     * @throws SmartsheetException the smartsheet exception
604
     */
605
    @Override
606
    public ReportColumn getReportColumn(long reportId, long columnVirtualId) throws SmartsheetException {
607
        return getReportColumn(reportId, columnVirtualId, null);
×
608
    }
609

610
    /**
611
     * Get a single column from a report.
612
     * <p>
613
     * It mirrors to the following Smartsheet REST API method: GET /reports/{reportId}/columns/{columnVirtualId}
614
     *
615
     * @param reportId        the ID of the report
616
     * @param columnVirtualId the virtual ID of the column
617
     * @param level           compatibility level
618
     * @return the ReportColumn
619
     * @throws SmartsheetException the smartsheet exception
620
     */
621
    @Override
622
    public ReportColumn getReportColumn(long reportId, long columnVirtualId, Integer level) throws SmartsheetException {
623
        String path = REPORTS_PATH + reportId + COLUMNS_PATH + columnVirtualId;
×
624
        Map<String, Object> parameters = new HashMap<>();
×
625
        if (level != null) {
×
626
            parameters.put("level", level);
×
627
        }
628
        path += QueryUtil.generateUrl(null, parameters);
×
629

630
        return this.getResource(path, ReportColumn.class);
×
631
    }
632

633
    /**
634
     * Delete a single column from a report.
635
     * <p>
636
     * It mirrors to the following Smartsheet REST API method: DELETE /reports/{reportId}/columns/{columnVirtualId}
637
     *
638
     * @param reportId        the ID of the report
639
     * @param columnVirtualId the virtual ID of the column
640
     * @throws SmartsheetException the smartsheet exception
641
     */
642
    @Override
643
    public void deleteReportColumn(long reportId, long columnVirtualId) throws SmartsheetException {
644
        this.deleteResource(REPORTS_PATH + reportId + COLUMNS_PATH + columnVirtualId, ReportColumn.class);
×
645
    }
×
646

647
    /**
648
     * Updates a report column.
649
     * <p>
650
     * It mirrors to the following Smartsheet REST API method: PUT /reports/{reportId}/columns/{columnVirtualId}
651
     *
652
     * @param reportId        the ID of the report
653
     * @param columnVirtualId the virtual ID of the column to update
654
     * @param request         the UpdateReportColumnRequest containing the fields to update
655
     * @return the updated ReportColumn
656
     * @throws SmartsheetException the smartsheet exception
657
     */
658
    @Override
659
    public ReportColumn updateReportColumn(
660
            long reportId, long columnVirtualId, UpdateReportColumnRequest request) throws SmartsheetException {
661
        return this.updateResource(REPORTS_PATH + reportId + COLUMNS_PATH + columnVirtualId,
×
662
                ReportColumn.class, request);
663
    }
664

665
    private void setRequestEntity(HttpRequest request, Object object) throws JSONSerializerException {
666
        ByteArrayOutputStream objectBytesStream = new ByteArrayOutputStream();
×
667
        this.smartsheet.getJsonSerializer().serialize(object, objectBytesStream);
×
668
        HttpEntity entity = new HttpEntity();
×
669
        entity.setContentType(JSON_CONTENT_TYPE);
×
670
        entity.setContent(new ByteArrayInputStream(objectBytesStream.toByteArray()));
×
671
        entity.setContentLength(objectBytesStream.size());
×
672
        request.setEntity(entity);
×
673
    }
×
674
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc