diff --git a/src/main/java/lol/pbu/z4j/client/SearchClient.java b/src/main/java/lol/pbu/z4j/client/SearchClient.java
index 26cdfd0..f27f1f7 100644
--- a/src/main/java/lol/pbu/z4j/client/SearchClient.java
+++ b/src/main/java/lol/pbu/z4j/client/SearchClient.java
@@ -21,6 +21,7 @@
import io.micronaut.http.client.annotation.Client;
import io.micronaut.retry.annotation.Retryable;
import jakarta.validation.Valid;
+import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.NotNull;
import lol.pbu.z4j.model.SearchExportType;
import lol.pbu.z4j.model.SearchResponse;
@@ -56,7 +57,34 @@ public interface SearchClient {
/**
*
{@summary Export Search Results}
- * Exports a set of results. See Query syntax for the syntax of the {@code query} parameter.
Use this endpoint for search queries that will return more than 1000 results. The result set is ordered only by the {@code created_at} attribute.
The search only returns results of a single object type. The following object types are supported: ticket, organization, user, or group.
You must specify the type in the {@code filter[type]} parameter. Searches with type in the query string will result in an error.
Allowed for Agents Pagination
See Pagination.
Returns a maximum of 1000 records per page. The number of results shown in a page is determined by the {@code page[size]} parameter.
Note: You may experience a speed reduction or a timeout if you request 1000 results per page and you have many archived tickets in the results. Try reducing the number of results per page. We recommend 100 results per page.
The cursor specified by the {@code after_cursor} property in a response expires after one hour.
For more information on cursor-based pagination, see the following articles:
Export Search Results Limits
This API endpoint is rate-limited to 100 requests per minute per account. The limit also counts towards the global API rate limit.
+ * Exports a set of results. See Query
+ * syntax for the syntax of the {@code query} parameter.
Use this endpoint for search queries that will
+ * return more than 1000 results. The result set is ordered only by the {@code created_at} attribute.
The search
+ * only returns results of a single object type. The following object types are supported: ticket, organization, user,
+ * or group.
You must specify the type in the {@code filter[type]} parameter. Searches with type in the query
+ * string will result in an error.
Allowed for Agents Pagination
+ *
+ * - Cursor
+ * pagination
+ *
+ *
See Pagination.
+ * Returns a maximum of 1000 records per page. The number of results shown in a page is determined by the {@code
+ * page[size]} parameter.
Note: You may experience a speed reduction or a timeout if you
+ * request 1000 results per page and you have many archived tickets in the results. Try reducing the number of results
+ * per page. We recommend 100 results per page.
The cursor specified by the {@code after_cursor} property in a
+ * response expires after one hour.
For more information on cursor-based pagination, see the following
+ * articles:
+ * Export Search Results Limits
This API endpoint is rate-limited to 100 requests per minute per account.
+ * The limit also counts towards the global API rate
+ * limit.
*
* @param query Returns the search results. See Query syntax for details on the {@code query} parameter. For details on the query syntax, see the Zendesk Support search reference. (required)
* @param pageSize The number of results shown in a page. (required)
@@ -69,7 +97,7 @@ public interface SearchClient {
@Get("/api/v2/search/export")
Mono<@Valid SearchResponse> export(
@QueryValue("query") @NotNull String query,
- @QueryValue("page[size]") @NotNull Integer pageSize,
+ @QueryValue("page[size]") @NotNull @Max(1000) Integer pageSize,
@QueryValue("page[after]") @NotNull String pageAfter,
@QueryValue("filter[type]") @NotNull SearchExportType filterType,
@QueryValue("include") @Nullable String include
@@ -77,12 +105,20 @@ public interface SearchClient {
/**
* {@summary List Search Results}
- * Returns the search results. See Query syntax for details on the {@code query} parameter.
Use the ampersand character (&) to append the {@code sort_by} or {@code sort_order} parameters to the URL.
For examples, see Searching with Zendesk API.
This endpoint has its own rate limit. The rate limit counts towards the global API rate limit. See Limits.
Allowed For Agents
Pagination
Offset pagination may result in duplicate results when paging. You can also use the Export Search Results endpoint, which uses cursor-based pagination and doesn't return duplicate results. See Using cursor pagination for more information.
+ * Returns the search results. See Query
+ * syntax for details on the {@code query} parameter.
+ *
+ * This endpoint has its own rate limit. The rate limit counts towards the global API rate
+ * limit. See Limits.
+ * Allowed For Agents
*
* @param query Returns the search results. See Query syntax for details on the {@code query} parameter. For details on the query syntax, see the Zendesk Support search reference. (required)
* @param sortBy One of {@code updated_at}, {@code created_at}, {@code priority}, {@code status}, or {@code ticket_type}. Defaults to sorting by relevance (optional)
* @param sortOrder Defaults to descending (optional)
* @param include Sideloads to include in the response. Accepts a comma-separated list of values. The available sideloads depend on the search result types. (optional)
+ * @param page The page number to retrieve. (optional)
+ * @param perPage The count of results to include in each page. (optional)
* @return Success response (status code 200)
* or Error response (status code 400)
*/
@@ -91,6 +127,8 @@ public interface SearchClient {
@QueryValue("query") @NotNull String query,
@QueryValue("sort_by") @Nullable SortBy sortBy,
@QueryValue("sort_order") @Nullable SortOrder sortOrder,
- @QueryValue("include") @Nullable String include
+ @QueryValue("include") @Nullable String include,
+ @QueryValue("page") @Nullable Integer page,
+ @QueryValue("per_page") @Nullable @Max(100) Integer perPage
);
}
diff --git a/src/main/java/lol/pbu/z4j/client/TicketClient.java b/src/main/java/lol/pbu/z4j/client/TicketClient.java
index 63e2955..d7c92f3 100644
--- a/src/main/java/lol/pbu/z4j/client/TicketClient.java
+++ b/src/main/java/lol/pbu/z4j/client/TicketClient.java
@@ -85,7 +85,7 @@ public interface TicketClient {
* {@summary List Ticket Fields}
* Returns a list of all system and custom ticket fields in your account.
For end users, only the ticket fields with visible_in_portal set to true are returned.
Consider caching this resource to use with the{@link TicketClient}.
Allowed For
*
- * @param locale Forces the {@code titleInPortal} property to return a dynamic content variant for the specified locale. Only accepts {@link LocaleClient#listLocales() active locale ids}. (optional)
+ * @param localeAbbreviation Forces the {@code titleInPortal} property to return a dynamic content variant for the specified locale. Only accepts {@link LocaleClient#listLocales() active locale ids}. (optional)
* @param creator Includes the {@code creatorUserId} and {@code creatorAppName} properties in the response. If the ticket field is created by an app, {@code creatorAppName} is the name of the app and {@code creatorUserId} is {@code -1}. If the ticket field is not created by an app, {@code creatorAppName} is null. (optional)
* @return Success response (status code 200)
*/
diff --git a/src/test/groovy/lol/pbu/z4j/client/SearchClientSpec.groovy b/src/test/groovy/lol/pbu/z4j/client/SearchClientSpec.groovy
index 3875797..c810bf0 100644
--- a/src/test/groovy/lol/pbu/z4j/client/SearchClientSpec.groovy
+++ b/src/test/groovy/lol/pbu/z4j/client/SearchClientSpec.groovy
@@ -17,9 +17,7 @@ package lol.pbu.z4j.client
import io.micronaut.http.client.exceptions.HttpClientResponseException
import lol.pbu.z4j.Z4jSpec
-import lol.pbu.z4j.model.SearchExportType
-import lol.pbu.z4j.model.SortBy
-import lol.pbu.z4j.model.SortOrder
+import lol.pbu.z4j.model.*
import spock.lang.Shared
import spock.lang.Unroll
@@ -27,16 +25,20 @@ class SearchClientSpec extends Z4jSpec {
@Shared
SearchClient adminSearchClient, agentSearchClient, userSearchClient
+ @Shared
+ TicketClient ticketClient
+
def setupSpec() {
adminSearchClient = adminCtx.getBean(SearchClient.class)
agentSearchClient = agentCtx.getBean(SearchClient.class)
userSearchClient = userCtx.getBean(SearchClient.class)
}
+ @SuppressWarnings("GroovyAssignabilityCheck")
@Unroll("an #clientName user can run the list method with sortby: #sortBy, sortOrder: #sortOrder and include: #include")
void "can run the list method"(String clientName, SearchClient client, SortBy sortBy, SortOrder sortOrder, String include) {
when:
- client.list(faker.bluey().quote(), sortBy, sortOrder, include).block()
+ client.list(faker.bluey().quote(), sortBy, sortOrder, include, null, null).block()
then:
noExceptionThrown()
@@ -59,10 +61,50 @@ class SearchClientSpec extends Z4jSpec {
[client, clientName] << [[adminSearchClient, "admin"], [agentSearchClient, "agent"]]
}
+
+ @SuppressWarnings("GroovyAssignabilityCheck")
+ @Unroll("an #clientName user can paginate the list method with sortby: #sortBy, sortOrder: #sortOrder and include: #include")
+ void "can query the list method when results include more than the page size"(
+ String clientName, SearchClient client, SortBy sortBy, SortOrder sortOrder, String include) {
+ given:
+ if (null == ticketClient) {
+ ticketClient = adminCtx.getBean(TicketClient.class)
+ }
+ if (client.count("frank").block().getCount() < 5) {
+ (1..5).each {
+ TicketComment ticketComment = new TicketComment().setBody("frank " + faker.chuckNorris().fact())
+ TicketCreateRequest createTicketRequest = new TicketCreateRequest(new TicketCreateInput(ticketComment))
+ createTicketRequest.ticket.setSubject(faker.chuckNorris().fact())
+ ticketClient.createTicket(createTicketRequest).block()
+ }
+ }
+
+ when:
+ def page = 1
+ List responses = []
+ SearchResponse response = client.list("frank", sortBy, sortOrder, include, page, 2).block()
+ responses << response
+ while (response.nextPage != null) {
+ page++
+ response = client.list("frank", sortBy, sortOrder, include, page, 2).block()
+ responses << response
+ }
+
+ then:
+
+ noExceptionThrown()
+
+ where:
+ [[client, clientName], sortBy, sortOrder, include] << [[[adminSearchClient, "admin"], [agentSearchClient, "agent"]],
+ [SortBy.values(), null].flatten(),
+ [SortOrder.values(), null].flatten(),
+ [null, faker.cat().name()]].combinations()
+ }
+
@Unroll("a simple user querying the list method fails with #sortBy, #sortOrder and #include")
void "cannot run searchClient.list()"(SearchClient client, SortBy sortBy, SortOrder sortOrder, String include) {
when:
- client.list(faker.bluey().quote(), sortBy, sortOrder, include).block()
+ client.list(faker.bluey().quote(), sortBy, sortOrder, include, null, null).block()
then:
thrown(HttpClientResponseException)
@@ -103,4 +145,3 @@ class SearchClientSpec extends Z4jSpec {
["organizations"]].combinations()
}
}
-