Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 3.03 KB

misc.md

File metadata and controls

47 lines (36 loc) · 3.03 KB

Store, users & logs

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, in Store order.
  • iterate(?StoreListOptions $options = null, ?int $chunkSize = null): iterable: lazily yields the Actors in Store order. The limit option caps the total (unset for all), $chunkSize is the page size.
  • search(StoreSearchOptions $options): StoreSearchResult: the Actors that match a query best, by relevance. The API answers a search with one page of at most 100 Actors, ignores offset, and does not report how many Actors match, so a search cannot be paged or iterated. A result with as many Actors as getLimit() can be cut off: narrow the query or use the filters. getItems() returns the Actors and getLimit() the limit the API applied, and the result can be iterated and counted. An empty query or a limit that is not positive throws InvalidArgumentException when the options are created.
$result = $client->store()->search(new StoreSearchOptions('scraper', limit: 10));
foreach ($result->getItems() as $item) {
    echo $item->getName() . PHP_EOL;
}

$shown = 0;
// 50 is the page size. The limit option would cap the total.
foreach ($client->store()->iterate(new StoreListOptions(category: 'AI_AND_ML'), 50) as $item) {
    echo $item->getName() . PHP_EOL;
    if (++$shown >= 5) {
        break;
    }
}

Users — $client->me() / $client->user($id)

  • get(): ?User: the private account details, such as the plan and email, are in toArray() for me() and for a user ID fetched with a token of that account. A token with limited permissions never gets them, and me() omits plan, email and profile when called from an Actor run. With a proxy password as the token, the API returns only plan.availableProxyGroups, effectivePlatformFeatures and isPaying, so getId() and getUsername() are null.
  • monthlyUsage(?string $date = null): array: the monthly usage of the cycle that contains $date (YYYY-MM-DD), by default the current month.
  • limits(): array, updateLimits(mixed $newLimits): void: the account limits. These three methods work for me() and for any user ID the token may access.
$me = $client->me()->get();
$usage = $client->me()->monthlyUsage('2026-06-01');
$limits = $client->me()->limits();
$publicProfile = $client->user('some-username')->get();

Logs — $client->log($buildOrRunId)

  • get(?LogOptions $options = null): ?string: the log as text, with the exact bytes the API sent.
  • stream(?LogOptions $options = null, int|float|string|null $timeoutSecs = null): ?StreamInterface: a live stream of the log, or null if the log does not exist. A client without an ID, such as run()->log(), throws on a 404, like get(). Opening the stream is retried like any request, and a failure while the log is being read is not. The default timeout is the long tier.
$log = $client->log('RUN_OR_BUILD_ID')->get(new LogOptions(raw: true));