Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to the Rust Apify API client are documented here. The format
based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres
to [Semantic Versioning](https://semver.org/).

## [0.19.0] - 2026-11-27

### Fixed
- `StoreCollectionClient::iterate` with a non-empty `search` fetches the single page the API
returns and stops, instead of repeating the same Actors.

### Changed
- Documented the Store search, `limit`, `category`, and `sort_by` semantics on `StoreListOptions`
and in the docs, and deprecated `StoreListOptions::sort_by`, which the API ignores.
- `ActorVersionCollectionClient::create` and `ActorVersionClient::update` use the `Long` timeout
tier by default, since a version can carry its source files.

## [0.18.0] - 2026-11-20

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apify-client"
version = "0.18.0"
version = "0.19.0"
authors = ["Apify Technologies <support@apify.com>"]
description = "Rust client for the Apify API (https://apify.com)."
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It provides a resource-oriented, async interface that follows the

```toml
[dependencies]
apify-client = "0.18"
apify-client = "0.19"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
serde_json = "1" # for the `serde_json::Value` responses used in the Quick start
```
Expand Down Expand Up @@ -49,7 +49,7 @@ instead, disable the default features and name `rustls`. The `"zstd"` entry keep
so drop it if you do not need it:

```toml
apify-client = { version = "0.18", default-features = false, features = ["rustls", "zstd"] }
apify-client = { version = "0.19", default-features = false, features = ["rustls", "zstd"] }
```

The `rustls` feature requires `rustls-webpki` 0.103.16 or newer and `webpki-roots` 1.0.10 or
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Add the crate and an async runtime:

```toml
[dependencies]
apify-client = "0.18"
apify-client = "0.19"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
```

Expand Down
3 changes: 2 additions & 1 deletion docs/actors.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,4 +407,5 @@ when it is `None`.
Creating a version needs `versionNumber` and `sourceType` in the body, and so does every item of
the `versions` array in an Actor create or update body. The writable source types are
`SOURCE_FILES`, `GIT_REPO`, `TARBALL` and `GITHUB_GIST`; `SOURCE_CODE` can be read but not sent.
Updating a version needs no required field.
Updating a version needs no required field. `create` and `update` use the `Long` timeout tier by
default, since a version can carry its source files; set another one with `with_timeout`.
15 changes: 14 additions & 1 deletion docs/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
| `iterate(options)` | `StoreListOptions` | `StoreActorIterator` | Lazy, page-fetching iterator. |

`StoreListOptions`: `offset`, `limit`, `search`, `sort_by`, `category`, `username`,
`pricing_model`, `include_unrunnable_actors`, `allows_agentic_users`, `response_format`.
`pricing_model`, `include_unrunnable_actors`, `allows_agentic_users`, `response_format`,
`include_input_schema`.
`limit` means a single page's size for `list`, but a cap on the *total* number of
items yielded for `iterate` (see below).

With a non-empty `search`, the API ranks the results by relevance and returns a single page of at
most 100 items: `offset` is ignored, a larger `limit` is reduced to 100, and there is no second
page. Without it, a page has at most 1000 items, or 10 with `include_input_schema`. `sort_by` is
deprecated: the API accepts it and ignores it, so sort the results on the client if you need a
different order. `category` takes one or more category IDs separated by commas, such as
`AI_AND_ML`; an Actor must match all of them, and an unknown category makes the API answer with a
`400` error.

`StoreActorIterator` is a type alias for `ListIterator<ActorStoreListItem>` (the shared iterator
returned by every collection's `iterate`), re-exported at the crate root alongside `ListIterator`
itself. Its `next()` is `async` and fallible — it returns
Expand Down Expand Up @@ -50,6 +59,10 @@ while let Some(actor) = iter.next().await? {
# }
```

With a non-empty `search`, the API returns a single page and ignores `offset`, so the iterator
fetches that one page of at most 100 Actors and stops; `with_chunk_size` has no effect then. An
empty `search` is the same as none.

`ActorStoreListItem` (from `apify_client::models`) is the element type yielded by both `list`
and the iterator. Its fields:

Expand Down
5 changes: 4 additions & 1 deletion src/clients/actor_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ impl ActorVersionClient {
}

/// Updates the version with the given fields.
///
/// The request uses the `Long` timeout tier by default, since the version can carry its
/// source files. Set another one with [`with_timeout`](Self::with_timeout).
pub async fn update<T: Serialize>(&self, new_fields: &T) -> ApifyClientResult<ActorVersion> {
update_resource(&self.ctx, None, new_fields, Timeout::Short).await
update_resource(&self.ctx, None, new_fields, Timeout::Long).await
}

/// Deletes the version.
Expand Down
5 changes: 4 additions & 1 deletion src/clients/actor_version_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ impl ActorVersionCollectionClient {
}

/// Creates a new Actor version.
///
/// The request uses the `Long` timeout tier by default, since the version can carry its
/// source files. Set another one with [`with_timeout`](Self::with_timeout).
pub async fn create<T: Serialize>(&self, version: &T) -> ApifyClientResult<ActorVersion> {
create_resource(&self.ctx, &QueryParams::new(), version, Timeout::Short).await
create_resource(&self.ctx, &QueryParams::new(), version, Timeout::Long).await
}
}
37 changes: 27 additions & 10 deletions src/clients/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type PageFetcher<T> = Box<dyn Fn(i64, Option<i64>) -> PageFuture<T> + Send + Syn
/// Collections whose listing does not fit this shape build their iterator directly instead:
/// the run listing takes a separate `filter` argument, dataset items use `list_items::<T>`, and
/// the listings that are not paginated (an Actor's versions and a version's env vars) use
/// `single_page_iterator!`.
/// `single_page_iterator!`. The Store listing uses this macro, except for a non-empty search,
/// which returns one page and ignores `offset`, so it uses `single_page_iterator!` as well.
macro_rules! list_iterator {
($self:expr, $options:expr, $list:ident) => {{
let client = $self.clone();
Expand All @@ -52,9 +53,12 @@ macro_rules! list_iterator {
}
pub(crate) use list_iterator;

/// Generates the body of the `iterate()` method of a collection whose endpoint is not
/// offset-paginated: it has a no-argument `list()` method and returns every item in one response.
/// The resulting [`ListIterator`] calls `list` exactly once and then completes.
/// Generates the body of the `iterate()` method of a collection that is read in a single request.
/// Without more arguments, the endpoint is not offset-paginated and the collection has a
/// no-argument `list()` method. With `options` and a list method name, it calls `$list(options)`
/// once with the options as given (no `offset` or `limit` override), for a request that ignores
/// `offset`, such as a Store search. The resulting [`ListIterator`] calls `list` exactly once and
/// then completes.
macro_rules! single_page_iterator {
($self:expr) => {{
let client = $self.clone();
Expand All @@ -65,6 +69,17 @@ macro_rules! single_page_iterator {
},
))
}};
($self:expr, $options:expr, $list:ident) => {{
let client = $self.clone();
let options = $options;
$crate::clients::pagination::ListIterator::new_single_page(Box::new(
move |_offset, _page_limit| {
let client = client.clone();
let options = options.clone();
Box::pin(async move { client.$list(options).await })
},
))
}};
}
pub(crate) use single_page_iterator;

Expand Down Expand Up @@ -124,8 +139,9 @@ pub struct ListIterator<T> {
remaining: Option<i64>,
/// Page size to request per fetch; `None` = let the API choose its default page size.
chunk_size: Option<i64>,
/// When `true`, the underlying endpoint is not offset-paginated: the first fetch returns the
/// whole result set, so the iterator stops after it rather than requesting a second page.
/// When `true`, the underlying endpoint is not offset-paginated, or ignores `offset` for the
/// request (a Store search): the first fetch returns the only page, so the iterator stops
/// after it rather than requesting a second page.
single_page: bool,
/// Set once the listing has been fully consumed.
exhausted: bool,
Expand All @@ -148,9 +164,10 @@ impl<T> ListIterator<T> {
}

/// Builds an iterator over an endpoint that is **not** offset-paginated (it returns every
/// item in one response, e.g. an Actor version's environment variables). `fetch` is called
/// exactly once; the iterator does not attempt a second page, so it does not depend on the
/// endpoint reporting a page `limit` and cannot refetch the same items.
/// item in one response, e.g. an Actor version's environment variables) or that ignores
/// `offset` for the request at hand (a Store search). `fetch` is called exactly once; the
/// iterator does not attempt a second page, so it does not depend on the endpoint reporting a
/// page `limit` and cannot refetch the same items.
pub(crate) fn new_single_page(fetch: PageFetcher<T>) -> Self {
Self {
single_page: true,
Expand Down Expand Up @@ -222,7 +239,7 @@ impl<T> ListIterator<T> {
// Only a page that scanned nothing, or the caller's cap, ends the walk, which costs one
// extra request at the end.
if self.single_page {
// Non-paginated endpoint: everything came back in one response.
// Single-page listing: the first fetch is the only page.
self.exhausted = true;
} else if scanned == 0 {
self.exhausted = true;
Expand Down
41 changes: 31 additions & 10 deletions src/clients/store_collection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Client for browsing the Apify Store (`/v2/store`).

use crate::clients::base::{list_resource, ResourceContext};
use crate::clients::pagination::{list_iterator, ListIterator};
use crate::clients::pagination::{list_iterator, single_page_iterator, ListIterator};
use crate::common::{PaginationList, QueryParams};
use crate::error::ApifyClientResult;
use crate::http_client::HttpClient;
Expand All @@ -18,26 +18,38 @@ pub type StoreActorIterator = ListIterator<ActorStoreListItem>;
/// Options for searching the Apify Store.
#[derive(Debug, Default, Clone)]
pub struct StoreListOptions {
/// Number of items to skip.
/// Number of items to skip. The API ignores it when a non-empty `search` is used.
pub offset: Option<i64>,
/// Item limit. Its meaning depends on the method: for [`StoreCollectionClient::list`] it is a
/// single page's size (the maximum items that one call returns); for
/// Item limit. The default and the maximum are 1000. When a non-empty `search` is used,
/// they are 100, and a larger value is reduced to 100. With `include_input_schema`, they are
/// 10. Its meaning depends on the method: for [`StoreCollectionClient::list`] it is a single
/// page's size (the maximum items that one call returns); for
/// [`StoreCollectionClient::iterate`] it is a cap on the *total* number of items yielded across
/// all pages. See each method's docs.
pub limit: Option<i64>,
/// Full-text search query.
/// Search query. With a non-empty query, the API ranks the results by relevance and returns a
/// single page of at most 100 items: `offset` is ignored and there is no second page. To
/// narrow the results, use `category`, `username`, or `pricing_model`.
pub search: Option<String>,
/// Sort key (e.g. `popularity`, `newest`).
/// Deprecated and ignored by the API, which accepts it for backward compatibility. Results
/// are ordered by relevance when a non-empty `search` is used, and by Store position
/// otherwise. Sort the results on the client if you need a different order.
#[deprecated(note = "the API ignores `sortBy`: sort the results on the client")]
pub sort_by: Option<String>,
/// Filter by category.
/// Filter by category. Accepts one or more category IDs separated by commas, case-insensitive
/// (for example `AI_AND_ML`). An Actor must match all of the listed categories. An unknown
/// category makes the API answer with a `400` error.
pub category: Option<String>,
/// Filter by owner username.
pub username: Option<String>,
/// Filter by pricing model: `FREE`, `PRICE_PER_DATASET_ITEM` or `PAY_PER_EVENT`.
pub pricing_model: Option<String>,
/// Include Actors that the current user cannot run (e.g. needing a missing integration).
/// By default, results exclude Actors that are not safe to run automatically, such as Actors
/// from developers who have not passed KYC or full-permission Actors without a large user
/// base. Set to `true` to bypass this safety filtering and include all Actors.
pub include_unrunnable_actors: Option<bool>,
/// Filter to Actors that allow agentic (x402/Skyfire) users.
/// If `true`, returns only Actors that allow agentic users. If `false`, returns only Actors
/// that do not allow agentic users.
pub allows_agentic_users: Option<bool>,
/// Response format requested from the API (`full` or `agent`, the API default is `full`).
pub response_format: Option<String>,
Expand Down Expand Up @@ -83,10 +95,19 @@ impl StoreCollectionClient {
/// [`list`](Self::list) where `limit` is a single page's size. Set the per-page fetch size
/// with [`with_chunk_size`](crate::ListIterator::with_chunk_size); see
/// [`ListIterator`] for details.
///
/// With a non-empty `options.search`, the API returns a single page of at most 100 Actors and
/// ignores `offset`, so the iterator fetches that one page and stops. `with_chunk_size` has no
/// effect then, and `options.limit` is sent as given.
pub fn iterate(&self, options: StoreListOptions) -> StoreActorIterator {
list_iterator!(self, options, list)
// The API treats an empty search as no search and pages through the Store as usual.
match options.search.as_deref() {
Some(search) if !search.is_empty() => single_page_iterator!(self, options, list),
_ => list_iterator!(self, options, list),
}
}

#[allow(deprecated)] // `sort_by` is deprecated, but it is still sent as the caller set it.
fn build_params(&self, options: &StoreListOptions) -> QueryParams {
let mut params = QueryParams::new();
params
Expand Down
36 changes: 36 additions & 0 deletions tests/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,39 @@ async fn list_store_with_input_schema() {
assert!(!page.items.is_empty(), "the Store lists Actors");
assert!(page.items.len() <= 3);
}

/// Simple GET: the deprecated `sort_by` is accepted by the Store endpoint, which ignores it, so
/// the order of the result is not asserted.
#[tokio::test(flavor = "multi_thread")]
#[allow(deprecated)] // The test covers the deprecated option.
async fn list_store_accepts_the_deprecated_sort_by() {
let client = require_client!();
let page = client
.store()
.list(StoreListOptions {
limit: Some(10),
sort_by: Some("popularity".to_string()),
..Default::default()
})
.await
.expect("listing the store with the deprecated sort_by should succeed");
assert!(!page.items.is_empty(), "the Store lists Actors");
}

/// Convenience: iterating a search fetches its single page and ends, without repeating Actors.
#[tokio::test(flavor = "multi_thread")]
async fn iterate_store_search_ends_with_unique_actors() {
let client = require_client!();
let mut iter = client.store().iterate(StoreListOptions {
search: Some("web scraper".to_string()),
..Default::default()
});
let mut ids = std::collections::HashSet::new();
let mut seen = 0;
while let Some(actor) = iter.next().await.expect("iterate the store search") {
seen += 1;
assert!(ids.insert(actor.id), "an Actor was yielded twice");
}
assert!(seen > 0, "the search yields at least one Actor");
assert!(seen <= 100, "a search returns at most 100 Actors");
}
67 changes: 66 additions & 1 deletion tests/unit_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::time::Duration;

use apify_client::{
ActorCallOptions, ActorStartOptions, ApifyClient, ApifyClientError, LastRunOptions,
LogRedirect, RequestCompression, TaskStartOptions, WaitForResources,
LogRedirect, RequestCompression, StoreListOptions, TaskStartOptions, WaitForResources,
};
use common::mock_backend::{client_with, MockBackend, MockOutcome};
use futures_util::StreamExt;
Expand Down Expand Up @@ -1699,6 +1699,71 @@ async fn iterate_steps_by_the_count_the_api_reports_when_it_exceeds_the_items_re
assert!(urls[2].contains("offset=6"), "{urls:?}");
}

/// With `search` the API returns one page and ignores `offset`, so the iterator stops after it
/// instead of requesting the same Actors again.
#[tokio::test]
async fn iterating_a_store_search_fetches_a_single_page() {
let backend = MockBackend::new(vec![MockOutcome::Status(
200,
br#"{"data":{"total":2,"count":2,"items":[{"id":"a"},{"id":"b"}]}}"#.to_vec(),
)]);
let client = client_with(backend.clone(), 0);

let actors = client
.store()
.iterate(StoreListOptions {
search: Some("scraper".to_string()),
limit: Some(10),
..Default::default()
})
.collect_all()
.await
.expect("ok");

let ids: Vec<&str> = actors.iter().map(|actor| actor.id.as_str()).collect();
assert_eq!(ids, ["a", "b"]);
let urls = backend.urls();
assert_eq!(urls.len(), 1, "{urls:?}");
assert!(urls[0].contains("search=scraper"), "{urls:?}");
assert!(urls[0].contains("limit=10"), "{urls:?}");
}

/// The API treats an empty `search` as no search and pages through the Store, so the iterator
/// keeps paging instead of stopping after the first page.
#[tokio::test]
async fn iterating_an_empty_store_search_pages_normally() {
let backend = MockBackend::new(vec![
MockOutcome::Status(
200,
br#"{"data":{"total":4,"count":2,"items":[{"id":"a"},{"id":"b"}]}}"#.to_vec(),
),
MockOutcome::Status(
200,
br#"{"data":{"total":4,"count":2,"items":[{"id":"c"},{"id":"d"}]}}"#.to_vec(),
),
MockOutcome::Status(
200,
br#"{"data":{"total":4,"count":0,"items":[]}}"#.to_vec(),
),
]);
let client = client_with(backend.clone(), 0);

let actors = client
.store()
.iterate(StoreListOptions {
search: Some(String::new()),
..Default::default()
})
.with_chunk_size(2)
.collect_all()
.await
.expect("ok");

assert_eq!(actors.len(), 4);
let urls = backend.urls();
assert!(urls[1].contains("offset=2"), "{urls:?}");
}

/// A streaming call retries an error status until the response starts, like a buffered call.
#[tokio::test]
async fn a_stream_is_retried_on_an_error_status_until_the_response_starts() {
Expand Down
Loading
Loading