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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.14.2

- `StoreListOptions::$sortBy` is deprecated, as the API ignores it.
- `store()->iterate()` with `search` makes one request, as the API returns a single page of at most 100 Actors and ignores `offset`. It used to repeat that page.
- `versions()->create()` and `version()->update()` use the `long` timeout tier by default, since a version can carry its source files.
- Documented the Store `category` filter and the `search` page limit.
- Raised PHPStan to level 9 and added an integration test for `user($id)->get()`.

## 0.14.1

- Synced with Apify OpenAPI spec `v2-2026-11-18T151559Z`: `UserClient::get()` returns only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying` for a proxy password.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apify/apify-client",
"description": "Official, experimental (AI-generated and AI-maintained) Apify API client for PHP: run Actors, manage storages (datasets, key-value stores, request queues), schedules, webhooks and more.",
"description": "Apify API client for PHP: run Actors, manage storages (datasets, key-value stores, request queues), schedules, webhooks and more.",
"type": "library",
"keywords": [
"apify",
Expand Down
3 changes: 2 additions & 1 deletion docs/actors.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ $response = $server->request('/search', new ActorServerRequestOptions(
- Single: `get(): ?ActorVersion`, `update(mixed $newFields): ActorVersion`, `delete(): void`.

The endpoint returns all versions in one response, so `list()` and `iterate()` take no options and `iterate()`
makes one request.
makes one request. `create()` and `update()` use the `long` timeout tier by default, since a version can carry its
source files.

```php
$version = $client->actor('me~my-actor')->versions()->create([
Expand Down
4 changes: 2 additions & 2 deletions docs/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Snippets assume `$client = new ApifyClient('my-api-token');` and imported types.
## Apify Store — `$client->store()`

- `list(?StoreListOptions $options = null): PaginationList`: one page of Store Actors.
- `iterate(?StoreListOptions $options = null, ?int $chunkSize = null): iterable`: lazily yields the matching Actors. The `limit` option caps the total (unset for all), `$chunkSize` is the page size.
- `iterate(?StoreListOptions $options = null, ?int $chunkSize = null): iterable`: lazily yields the matching Actors. The `limit` option caps the total (unset for all), `$chunkSize` is the page size. With `search`, the API returns one page of at most 100 Actors and ignores `offset`, so `iterate()` makes one request and ignores `$chunkSize`.

```php
$page = $client->store()->list(new StoreListOptions(search: 'scraper', limit: 10));

$shown = 0;
// 50 is the page size. The limit option would cap the total.
foreach ($client->store()->iterate(new StoreListOptions(search: 'scraper'), 50) as $item) {
foreach ($client->store()->iterate(new StoreListOptions(category: 'AI_AND_ML'), 50) as $item) {
echo $item->getName() . PHP_EOL;
if (++$shown >= 5) {
break;
Expand Down
16 changes: 8 additions & 8 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ The offset-based options classes — `ListOptions`, `ActorListOptions`, `Storage

It returns a copy of the options with the given `offset` and `limit`, preserving every other field.
The `iterate()` helpers use it internally to request successive pages, but you can also call it to
page manually through `list()` results — most useful for the Apify Store, whose collection is
otherwise only pageable via `iterate()`:
page manually through `list()` results, for example the Apify Store. A Store `search` is one page that ignores
`offset`, so page by a filter such as `category`:

```php
$options = new StoreListOptions(search: 'scraper');
$options = new StoreListOptions(category: 'AI_AND_ML');
for ($offset = 0; ; $offset += 100) {
$page = $client->store()->list($options->withPagination($offset, 100));
foreach ($page->getItems() as $item) {
Expand Down Expand Up @@ -80,11 +80,11 @@ Extra filters for `runs()->list()`, combined with a `ListOptions`.
For `store()->list()` / `store()->iterate()`.
| Field | Type | Description |
|---|---|---|
| `offset` | `?int` | Number of Actors to skip. |
| `limit` | `?int` | Maximum number of Actors to return. When iterating, caps the total across all pages (the per-page size is `iterate()`'s separate `$chunkSize` argument). |
| `search` | `?string` | Full-text search query. |
| `sortBy` | `?string` | The sort field (e.g. `popularity`, `newest`). |
| `category` | `?string` | Filter Actors by category. |
| `offset` | `?int` | Number of Actors to skip. The API ignores it with `search`. |
| `limit` | `?int` | Maximum number of Actors to return. When iterating, caps the total across all pages (the per-page size is `iterate()`'s separate `$chunkSize` argument). With `search`, the API returns at most 100. |
| `search` | `?string` | Full-text search query. The API ranks the results by relevance and returns one page of at most 100 Actors. |
| `sortBy` | `?string` | Deprecated: the API accepts it and ignores it. Sort the results on the client instead. |
| `category` | `?string` | Filter Actors by one or more comma-separated category IDs, such as `AI_AND_ML`. An Actor must match all of them. |
| `username` | `?string` | Filter Actors by owner username. |
| `pricingModel` | `?string` | Filter by pricing model (`FREE`, `PRICE_PER_DATASET_ITEM`, `PAY_PER_EVENT`). |
| `includeUnrunnableActors` | `?bool` | Include Actors the current user cannot run. |
Expand Down
4 changes: 1 addition & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Level 8 checks types, nullable access, and union types. Level 9 adds strict `mixed` handling. The client exposes
# `mixed` on purpose at the API boundary (JSON input, record values, `toArray()`), so it stays at level 8.
parameters:
level: 8
level: 9
paths:
- src
- tests
Expand Down
5 changes: 4 additions & 1 deletion src/Options/ActorServerRequestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public function appendTo(QueryParams $q): void
}
}

/** @param list<mixed> $values */
/**
* @param list<mixed> $values
* @phpstan-assert-if-true list<scalar> $values
*/
private static function isScalarList(array $values): bool
{
foreach ($values as $value) {
Expand Down
15 changes: 10 additions & 5 deletions src/Options/StoreListOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
final class StoreListOptions
{
public function __construct(
/** Number of Actors to skip. */
/** Number of Actors to skip. The API ignores it with {@code search}. */
public readonly ?int $offset = null,
/**
* The maximum number of Actors. When iterating, it caps the total over all pages, not the page size
* ({@code chunkSize}).
* ({@code chunkSize}). With {@code search}, the API returns at most 100.
*/
public readonly ?int $limit = null,
/** Full-text search query. */
/** Full-text search query. The API ranks the results by relevance and returns one page of at most 100 Actors. */
public readonly ?string $search = null,
/** The sort field (e.g. {@code "popularity"}, {@code "newest"}). */
/**
* The sort field.
*
* @deprecated The API ignores it. Results are ordered by relevance with {@code search} and by Store position
* otherwise, so sort them on the client.
*/
public readonly ?string $sortBy = null,
/** Filter Actors by category. */
/** Filter Actors by one or more comma-separated category IDs, such as {@code AI_AND_ML}. An Actor must match all of them. */
public readonly ?string $category = null,
/** Filter Actors by owner username. */
public readonly ?string $username = null,
Expand Down
5 changes: 3 additions & 2 deletions src/Resource/ActorVersionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ public function get(int|float|string|null $timeoutSecs = null): ?ActorVersion
}

/**
* Updates the version and returns it.
* Updates the version and returns it. The default timeout is the {@code long} tier, since the version can
* carry its source files.
*
* @param mixed $newFields any JSON-serializable fields
*/
public function update(mixed $newFields, int|float|string|null $timeoutSecs = null): ActorVersion
{
return new ActorVersion($this->ctx->updateResource('', $newFields, $this->ctx->resolveTimeout($timeoutSecs, TimeoutTiers::TIER_SHORT)));
return new ActorVersion($this->ctx->updateResource('', $newFields, $this->ctx->resolveTimeout($timeoutSecs, TimeoutTiers::TIER_LONG)));
}

/** Deletes the version. */
Expand Down
5 changes: 3 additions & 2 deletions src/Resource/ActorVersionCollectionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ public function iterate(int|float|string|null $timeoutSecs = null): Generator
}

/**
* Creates a version of the Actor.
* Creates a version of the Actor. The default timeout is the {@code long} tier, since the version can carry
* its source files.
*
* @param mixed $version any JSON-serializable version definition
*/
public function create(mixed $version, int|float|string|null $timeoutSecs = null): ActorVersion
{
return new ActorVersion($this->ctx->createResource(new QueryParams(), $version, $this->ctx->resolveTimeout($timeoutSecs, TimeoutTiers::TIER_SHORT)));
return new ActorVersion($this->ctx->createResource(new QueryParams(), $version, $this->ctx->resolveTimeout($timeoutSecs, TimeoutTiers::TIER_LONG)));
}
}
16 changes: 16 additions & 0 deletions src/Resource/StoreCollectionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,32 @@ public function list(?StoreListOptions $options = null, int|float|string|null $t
* Lazily yields Store Actors matching the options. The {@code limit} option caps the total ({@code null} for all) and
* {@code $chunkSize} sets the page size ({@code null} for the API's default).
*
* With {@code search}, the API ignores {@code offset} and returns one page of at most 100 Actors, so this makes
* one request with the {@code limit} option and ignores {@code $chunkSize}.
*
* @return Generator<int,ActorStoreListItem>
*/
public function iterate(?StoreListOptions $options = null, ?int $chunkSize = null, int|float|string|null $timeoutSecs = null): Generator
{
$options ??= new StoreListOptions();
if ($options->search !== null && $options->search !== '') {
return $this->iterateSearchPage($options, $timeoutSecs);
}
return ResourceContext::paginateOffset(
$options->offset ?? 0,
$options->limit,
$chunkSize,
fn (int $offset, ?int $pageLimit) => $this->list($options->withPagination($offset, $pageLimit), $timeoutSecs),
);
}

/**
* Yields the single page of a search, which the API cannot continue with an offset.
*
* @return Generator<int,ActorStoreListItem>
*/
private function iterateSearchPage(StoreListOptions $options, int|float|string|null $timeoutSecs): Generator
{
yield from $this->list($options->withPagination(null, $options->limit), $timeoutSecs)->getItems();
}
}
2 changes: 1 addition & 1 deletion src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class Version
* The semantic version of this client library (see https://semver.org/).
* Changes to the public interface other than additive ones are considered breaking changes.
*/
public const CLIENT_VERSION = '0.14.1';
public const CLIENT_VERSION = '0.14.2';

/**
* The version of the Apify OpenAPI specification this client was generated and verified
Expand Down
2 changes: 2 additions & 0 deletions tests/Integration/ActorRunIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function testIterateDatasetItemsReadsItemsWhileTheRunIsStillRunning(): vo
$statusWhenReceived = [];
$items = [];
foreach ($runClient->iterateDatasetItems(new RunIterateDatasetItemsOptions(pollIntervalSecs: 1)) as $item) {
/** @var array<string,mixed> $item */
$items[] = $item['n'];
$statusWhenReceived[] = $runClient->get()?->getStatus();
}
Expand Down Expand Up @@ -223,6 +224,7 @@ public function testMetamorphWithTheRunsOwnTokenTransformsTheRunKeepingItsId():
*/
private function createBuiltActor(ApifyClient $client, string $label, string $mainJs): string
{
/** @var array{versions: list<array{sourceFiles: list<array<string,mixed>>}>} $definition */
$definition = self::minimalActor(self::uniqueName($label));
$definition['versions'][0]['sourceFiles'][1]['content'] = $mainJs;
$actorId = (string) $client->actors()->create($definition)->getId();
Expand Down
5 changes: 4 additions & 1 deletion tests/Integration/DatasetIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function testIterateDatasetItems(): void
$values = [];
// chunkSize=2 across 5 items => three pages (2, 2, 1).
foreach ($dataset->iterateItems(new DatasetListItemsOptions(), 2) as $item) {
/** @var array<string,mixed> $item */
$values[] = $item['n'];
}
sort($values);
Expand Down Expand Up @@ -140,7 +141,9 @@ public function testDatasetCrudFlow(): void
$page = $dataset->listItems(new DatasetListItemsOptions());
self::assertSame(3, $page->getCount());
self::assertCount(3, $page->getItems());
self::assertSame(1, $page->getItems()[0]['n']);
/** @var array<string,mixed> $first */
$first = $page->getItems()[0];
self::assertSame(1, $first['n']);
// isDesc() is sourced from the server's X-Apify-Pagination-Desc response header.
self::assertFalse($page->isDesc());

Expand Down
20 changes: 20 additions & 0 deletions tests/Integration/StoreIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ public function testListStoreWithInputSchema(): void
self::assertNotEmpty($schemas, 'at least one Store Actor carries its input schema');
}

public function testListStoreAcceptsTheDeprecatedSortBy(): void
{
$client = $this->requireClient();
// The API accepts `sortBy` and ignores it, so the order is not asserted.
$page = $client->store()->list(new StoreListOptions(limit: 10, sortBy: 'popularity'));
self::assertNotEmpty($page->getItems());
}

public function testIterateStoreSearchReturnsOnePage(): void
{
$client = $this->requireClient();
$ids = [];
foreach ($client->store()->iterate(new StoreListOptions(search: 'website content crawler', limit: 20), 5) as $item) {
$ids[] = $item->getId();
}
self::assertNotEmpty($ids);
self::assertLessThanOrEqual(20, count($ids));
self::assertSame($ids, array_unique($ids), 'a search must not repeat its page');
}

public function testIterateStore(): void
{
$client = $this->requireClient();
Expand Down
10 changes: 10 additions & 0 deletions tests/Integration/UserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public function testGetOwnAccount(): void
self::assertNotSame('', $user->getId());
}

public function testGetAccountById(): void
{
$client = $this->requireClient();
$id = $client->me()->get()?->getId();
self::assertNotNull($id);
$user = $client->user($id)->get();
self::assertNotNull($user);
self::assertSame($id, $user->getId());
}

public function testGetMonthlyUsage(): void
{
$client = $this->requireClient();
Expand Down
4 changes: 3 additions & 1 deletion tests/Integration/ZstdCompressionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public function testDatasetItemsAreStoredFromAZstdBody(): void
self::waitForDatasetItemCount($items, 2);
$stored = $items->listItems()->getItems();
self::assertSame([1, 2], array_column($stored, 'n'));
self::assertSame($padding, $stored[0]['padding']);
/** @var array<string,mixed> $firstStored */
$firstStored = $stored[0];
self::assertSame($padding, $firstStored['padding']);
self::assertContains('zstd', $this->recorder->encodings);
} finally {
$client->dataset((string) $dataset->getId())->delete();
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ public function testDatasetItemsUseHeaderPagination(): void

self::assertSame(42, $page->getTotal());
self::assertSame(3, $page->getCount());
self::assertSame(1, $page->getItems()[0]['n']);
/** @var array<string,mixed> $first */
$first = $page->getItems()[0];
self::assertSame(1, $first['n']);
self::assertFalse($page->isDesc());
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/IterationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@ public function testStorePageCountIsCappedAtTheRequestedLimit(): void
self::assertStringContainsString('offset=2', (string) $transport->received[1]->getUri());
}

public function testStoreSearchIsASinglePageThatIgnoresTheOffset(): void
{
// With `search` the API ignores the offset, so a second request would repeat the first page forever.
$transport = (new MockTransport())
->queueResponse(200, self::pageWithCount(self::actors(1, 2), 2, 0));
$ids = [];
foreach ($this->client($transport)->store()->iterate(new StoreListOptions(search: 'scraper', limit: 50, offset: 7), 1) as $item) {
$ids[] = $item->getId();
}
self::assertSame(['a1', 'a2'], $ids);
self::assertSame(1, $transport->callCount());
$uri = (string) $transport->received[0]->getUri();
self::assertStringContainsString('search=scraper', $uri);
self::assertStringContainsString('limit=50', $uri);
self::assertStringNotContainsString('offset=', $uri);
}

public function testLimitCapStopsBeforeExhaustingPages(): void
{
// limit=2 with a big first page: only 2 items are yielded and no second request is made.
Expand Down Expand Up @@ -208,6 +225,7 @@ public function testDatasetIterateItemsPagesViaHeaders(): void
]);
$values = [];
foreach ($this->client($transport)->dataset('ds')->iterateItems(null, 2) as $item) {
/** @var array<string,mixed> $item */
$values[] = $item['n'];
}
self::assertSame([1, 2, 3], $values);
Expand Down Expand Up @@ -244,6 +262,7 @@ public function testDatasetIterateItemsAdvancesByScannedCountNotItemCount(): voi
]);
$values = [];
foreach ($this->client($transport)->dataset('ds')->iterateItems(new DatasetListItemsOptions(skipEmpty: true), 3) as $item) {
/** @var array<string,mixed> $item */
$values[] = $item['n'];
}
self::assertSame([0, 1, 3, 4, 5], $values);
Expand Down Expand Up @@ -279,6 +298,7 @@ public function testDatasetIterateItemsCapsScannedCountWhenUnwindInflatesItemsPa
]);
$values = [];
foreach ($this->client($transport)->dataset('ds')->iterateItems(new DatasetListItemsOptions(unwind: ['parts']), 2) as $item) {
/** @var array<string,mixed> $item */
$values[] = $item['n'];
}
self::assertSame(range(0, 11), $values);
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/MethodTierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static function tierCases(): iterable
yield 'Actor env var list' => [static fn (ApifyClient $c) => $c->actor('a')->version('0.1')->envVars()->list(), self::SHORT, self::PAGE_BODY];
yield 'Actor env var create' => [static fn (ApifyClient $c) => $c->actor('a')->version('0.1')->envVars()->create(new ActorEnvVar('N', 'v')), self::SHORT, self::ITEM_BODY];
yield 'Actor version list' => [static fn (ApifyClient $c) => $c->actor('a')->versions()->list(), self::SHORT, self::PAGE_BODY];
yield 'Actor version create' => [static fn (ApifyClient $c) => $c->actor('a')->versions()->create(['versionNumber' => '0.1']), self::SHORT, self::ITEM_BODY];
yield 'Actor version create' => [static fn (ApifyClient $c) => $c->actor('a')->versions()->create(['versionNumber' => '0.1']), self::LONG, self::ITEM_BODY];
yield 'Actor version update' => [static fn (ApifyClient $c) => $c->actor('a')->version('0.1')->update(['buildTag' => 'latest']), self::LONG, self::ITEM_BODY];
yield 'Dataset getOrCreate' => [static fn (ApifyClient $c) => $c->datasets()->getOrCreate('d'), self::SHORT, self::ITEM_BODY];
yield 'Key-value store getOrCreate' => [static fn (ApifyClient $c) => $c->keyValueStores()->getOrCreate('s'), self::SHORT, self::ITEM_BODY];
yield 'Request queue getOrCreate' => [static fn (ApifyClient $c) => $c->requestQueues()->getOrCreate('q'), self::SHORT, self::ITEM_BODY];
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/RunIterateDatasetItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static function ids(iterable $items): array
{
$ids = [];
foreach ($items as $item) {
/** @var array{id: int} $item */
$ids[] = $item['id'];
}
return $ids;
Expand Down
Loading
Loading