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

smartsheet / smartsheet-java-sdk / #66

26 Jun 2026 09:41AM UTC coverage: 59.997% (-0.006%) from 60.003%
#66

push

github

web-flow
Prepare for release v4.1.0 (#180)

4510 of 7517 relevant lines covered (60.0%)

0.6 hits per line

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

75.86
/src/main/java/com/smartsheet/api/internal/WebhookResourcesImpl.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.fasterxml.jackson.core.JsonParseException;
20
import com.fasterxml.jackson.databind.JsonMappingException;
21
import com.smartsheet.api.AuthorizationException;
22
import com.smartsheet.api.InvalidRequestException;
23
import com.smartsheet.api.ResourceNotFoundException;
24
import com.smartsheet.api.ServiceUnavailableException;
25
import com.smartsheet.api.SmartsheetException;
26
import com.smartsheet.api.WebhookResources;
27
import com.smartsheet.api.internal.http.HttpMethod;
28
import com.smartsheet.api.internal.http.HttpRequest;
29
import com.smartsheet.api.internal.http.HttpResponse;
30
import com.smartsheet.api.internal.util.QueryUtil;
31
import com.smartsheet.api.models.PagedResult;
32
import com.smartsheet.api.models.PaginationParameters;
33
import com.smartsheet.api.models.Webhook;
34
import com.smartsheet.api.models.WebhookSharedSecret;
35

36
import java.io.IOException;
37
import java.util.HashMap;
38
import java.util.Map;
39

40
public class WebhookResourcesImpl extends AbstractResources implements WebhookResources {
41
    private static final String WEBHOOKS_PATH = "webhooks/";
42

43
    public WebhookResourcesImpl(SmartsheetImpl smartsheet) {
44
        super(smartsheet);
1✔
45
    }
1✔
46

47
    /**
48
     * Gets the list of all Webhooks that the user owns (if a user generated token was used to make the request)
49
     * or the list of all Webhooks associated with the third-party app (if a third-party app made the request).
50
     * <p>
51
     * It mirrors to the following Smartsheet REST API method: GET /webhooks
52
     * <p>
53
     * Note: as of the Jun-03-2026 sunset date:
54
     * <ul>
55
     *   <li>{@code includeAll} is no longer honored by the server for this endpoint and is ignored if set on
56
     *       {@link PaginationParameters}. {@link PaginationParameters} remains a shared class — other endpoints
57
     *       still support {@code includeAll}.</li>
58
     *   <li>{@code pageSize} is server-capped at 10,000.</li>
59
     *   <li>{@code totalCount} and {@code totalPages} on the response are returned as {@code -1}.</li>
60
     *   <li>Webhooks are sorted by creation date (most recent first), no longer by name.</li>
61
     * </ul>
62
     * See <a href="https://developers.smartsheet.com/api/smartsheet/changelog#2025-08-04">Smartsheet API changelog 2025-08-04</a>.
63
     *
64
     * @param paging the object containing the pagination parameters
65
     * @return PagedResult object containing an array of Webhook objects.
66
     * @throws IllegalArgumentException    if any argument is null or empty string
67
     * @throws InvalidRequestException     if there is any problem with the REST API request
68
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
69
     * @throws ResourceNotFoundException   if the resource cannot be found
70
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
71
     * @throws SmartsheetException         if there is any other error during the operation
72
     */
73
    public PagedResult<Webhook> listWebhooks(PaginationParameters paging) throws SmartsheetException {
74
        String path = "webhooks";
1✔
75

76
        Map<String, Object> parameters = new HashMap<>();
1✔
77
        if (paging != null) {
1✔
78
            parameters = paging.toHashMap();
1✔
79
        }
80

81
        path += QueryUtil.generateUrl(null, parameters);
1✔
82
        return this.listResourcesWithWrapper(path, Webhook.class);
1✔
83
    }
84

85
    /**
86
     * Gets the Webhook specified in the URL.
87
     * <p>
88
     * It mirrors to the following Smartsheet REST API method: GET /webhooks/{webhookId}
89
     *
90
     * @param webhookId the ID of the webhook
91
     * @return the webhook resource.
92
     * @throws IllegalArgumentException    if any argument is null or empty string
93
     * @throws InvalidRequestException     if there is any problem with the REST API request
94
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
95
     * @throws ResourceNotFoundException   if the resource cannot be found
96
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
97
     * @throws SmartsheetException         if there is any other error during the operation
98
     */
99
    public Webhook getWebhook(long webhookId) throws SmartsheetException {
100
        return this.getResource(WEBHOOKS_PATH + webhookId, Webhook.class);
1✔
101
    }
102

103
    /**
104
     * Creates a new Webhook.
105
     * <p>
106
     * It mirrors to the following Smartsheet REST API method: POST /webhooks
107
     *
108
     * @param webhook the webhook to be created
109
     * @return the webhook resource.
110
     * @throws IllegalArgumentException    if any argument is null or empty string
111
     * @throws InvalidRequestException     if there is any problem with the REST API request
112
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
113
     * @throws ResourceNotFoundException   if the resource cannot be found
114
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
115
     * @throws SmartsheetException         if there is any other error during the operation
116
     */
117
    public Webhook createWebhook(Webhook webhook) throws SmartsheetException {
118
        return this.createResource("webhooks", Webhook.class, webhook);
1✔
119
    }
120

121
    /**
122
     * Updates the webhooks specified in the URL.
123
     * <p>
124
     * It mirrors to the following Smartsheet REST API method: PUT /webhooks/{webhookId}
125
     *
126
     * @param webhook the webhook to update
127
     * @return the updated webhook resource.
128
     * @throws IllegalArgumentException    if any argument is null or empty string
129
     * @throws InvalidRequestException     if there is any problem with the REST API request
130
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
131
     * @throws ResourceNotFoundException   if the resource cannot be found
132
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
133
     */
134
    public Webhook updateWebhook(Webhook webhook) throws SmartsheetException {
135
        return this.updateResource(WEBHOOKS_PATH + webhook.getId(), Webhook.class, webhook);
1✔
136
    }
137

138
    /**
139
     * Delete a webhook.
140
     * <p>
141
     * It mirrors to the following Smartsheet REST API method: DELETE /webhooks/{webhookId}
142
     *
143
     * @param webhookId the webhook Id
144
     * @throws IllegalArgumentException    if any argument is null or empty string
145
     * @throws InvalidRequestException     if there is any problem with the REST API request
146
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
147
     * @throws ResourceNotFoundException   if the resource cannot be found
148
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
149
     * @throws SmartsheetException         if there is any other error during the operation
150
     */
151
    public void deleteWebhook(long webhookId) throws SmartsheetException {
152
        this.deleteResource(WEBHOOKS_PATH + webhookId, Webhook.class);
1✔
153
    }
1✔
154

155
    /**
156
     * Resets the shared secret for the specified Webhook. For more information about how a shared secret is used,
157
     * see Authenticating Callbacks.
158
     * <p>
159
     * It mirrors to the following Smartsheet REST API method: POST /webhooks/{webhookId}/resetsharedsecret
160
     *
161
     * @param webhookId the webhook ID
162
     * @return the Webhook shared secret
163
     * @throws IllegalArgumentException    if any argument is null or empty string
164
     * @throws InvalidRequestException     if there is any problem with the REST API request
165
     * @throws AuthorizationException      if there is any problem with  the REST API authorization (access token)
166
     * @throws ResourceNotFoundException   if the resource cannot be found
167
     * @throws ServiceUnavailableException if the REST API service is not available (possibly due to rate limiting)
168
     * @throws SmartsheetException         if there is any other error during the operation
169
     */
170
    public WebhookSharedSecret resetSharedSecret(long webhookId) throws SmartsheetException {
171
        HttpRequest request = createHttpRequest(this.getSmartsheet().getBaseURI().resolve(WEBHOOKS_PATH +
1✔
172
                webhookId + "/resetsharedsecret"), HttpMethod.POST);
173

174
        HttpResponse response = getSmartsheet().getHttpClient().request(request);
1✔
175

176
        WebhookSharedSecret secret = null;
1✔
177
        switch (response.getStatusCode()) {
1✔
178
            case 200:
179
                try {
180
                    secret = this.smartsheet.getJsonSerializer().deserialize(WebhookSharedSecret.class,
1✔
181
                            response.getEntity().getContent());
1✔
182
                } catch (JsonParseException e) {
×
183
                    throw new SmartsheetException(e);
×
184
                } catch (JsonMappingException e) {
×
185
                    throw new SmartsheetException(e);
×
186
                } catch (IOException e) {
×
187
                    throw new SmartsheetException(e);
×
188
                }
1✔
189
                break;
190
            default:
191
                handleError(response);
×
192
        }
193

194
        getSmartsheet().getHttpClient().releaseConnection();
1✔
195
        return secret;
1✔
196
    }
197
}
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