Skip to content

Latest commit

 

History

History
136 lines (114 loc) · 8.84 KB

misc.md

File metadata and controls

136 lines (114 loc) · 8.84 KB

Store, users & logs

Apify Store: client.store()

Browse and search public Actors in Apify Store. client.store() returns a StoreCollectionClient. The API serves the Store in two ways, and the client has a method for each: list and iterate browse the whole Store in Store order, and search returns the Actors that match a query best.

Method Description
list(StoreListOptions) A page of Store Actors. Completes with PaginationList<ActorStoreListItem>.
iterate(StoreListOptions, Long chunkSize) A lazy Flow.Publisher<ActorStoreListItem> over all matches, fetching pages on demand. The options' limit caps the total number of rows read, which are the Actors yielded unless the API drops entries after counting them (null/unset or non-positive = all); chunkSize is the per-request page size (null = server default).
search(StoreSearchOptions) The Actors that match a query best, best match first, as a single page. Completes with StoreSearchResult.

StoreListOptions fields: offset (number of Actors to skip), limit (maximum number of Actors to return; the API default and maximum is 1000), and the filters below. The API has no option to change the Store order.

StoreSearchOptions takes the query in its constructor, which rejects a null or empty query, since the API answers an empty query with the Store listing. Its fields are limit (maximum number of Actors to return, a positive number; the API default and maximum is 100, and it reduces a larger value to 100, except with includeInputSchema: see below) and the filters below. There is no offset: the API ignores it for a search.

Filters of both options types: category (filter by one or more category IDs such as AI_AND_ML, comma-separated and case-insensitive; an Actor must match all of them, and an unknown category fails with a 400 error), username (filter Actors by owner username), pricingModel (filter by pricing model: FREE, PRICE_PER_DATASET_ITEM, PAY_PER_EVENT), includeUnrunnableActors (by default, the API leaves out Actors that are not safe to run automatically, such as Actors of developers who have not passed identity verification; true includes them), responseFormat (the response shape: full, the default, or agent, a reduced field set for LLM consumers with id, title, name, username, description, notice, badge, categories, and minimal stats, so the other getters of ActorStoreListItem return null), includeInputSchema (add each Actor's compact inputSchema; the API then defaults limit to 10 and rejects a larger value with a 400 error).

A search returns a single page of at most 100 Actors ranked by relevance. There is no next page, and the API does not report how many Actors match. StoreSearchResult therefore has only getItems() and getLimit(), the limit the API applied. When getItems().size() equals it, more Actors may match than were returned, so narrow the search with a more specific query or with category, username, or pricingModel. To go through the whole Store, use list or iterate.

// Publishers.collect() drains the whole publisher; fine here since `limit` already caps it.
// To stop early without fetching further pages, subscribe with your own Flow.Subscriber instead
// (request(1) at a time, cancel() once you have enough); see IterateStore.java in the examples.
List<ActorStoreListItem> items =
    Publishers.collect(client.store().iterate(new StoreListOptions().username("apify").limit(20L), 10L))
        .join();
items.forEach(item -> System.out.println(item.getUsername() + "/" + item.getName()));

// A search is one page of at most 100 Actors.
StoreSearchResult found =
    client.store().search(new StoreSearchOptions("crawler").limit(10L)).join();
found.getItems().forEach(item -> System.out.println(item.getUsername() + "/" + item.getName()));

ActorStoreListItem fields: getId(), getName(), getUsername(), getTitle(), getUserFullName(), getDescription(), getCategories() (List<String> of category IDs), getNotice(), getStats() (StoreActorStats: getTotalUsers(), getTotalRuns(), getTotalUsers7Days(), getTotalUsers30Days(), getTotalUsers90Days(), getActorReviewRating(), getActorReviewCount()), getCurrentPricingInfo() (PricingInfo: getPricingModel()), getIsVerified() (whether the developer has a verified identity), getBadge(), getPictureUrl(), getUserPictureUrl(), getUrl(), getReadmeSummary(). Any field not covered by a typed getter is still available via the inherited getExtra() (see the docs index).

Users: client.me() / client.user(id)

Method Description
get() Fetch the user. Completes with Optional<User> (public profile, plus private account details for me() or when a full-permission token of that user, or one that impersonates it, is used).
monthlyUsage() / monthlyUsage(String date) The user's monthly usage. date (any day within the target month, formatted YYYY-MM-DD) reports that month; null/empty reports the current month. Completes with JsonNode.
limits() The user's account and usage limits. Completes with JsonNode.
updateLimits(Object) Update the user's account and usage limits. Completes with no value (CompletableFuture<Void>).

The usage/limits methods work on me() and on user(id) (/v2/users/{userId}/usage/monthly and /v2/users/{userId}/limits), subject to what the API token may access.

Optional<User> me = client.me().get().join();
me.ifPresent(
    u -> {
      System.out.println("Account: " + u.getId());
      // email/plan/proxy/... are private fields: see "Which fields are set" below.
      System.out.println("Email: " + u.getEmail());
    });
JsonNode usage = client.me().monthlyUsage().join();

Which fields are set:

  • getUsername() is set, except for a proxy-password request (below), and getProfile() may be absent.
  • The private fields (listed below, including getId()) are set for me(), and for user(id) only when the request uses a full-permission API token of that user or a token that impersonates it.
  • getPlan(), getEmail(), and getProfile() are omitted when me() is requested from an Actor run.
  • A request authenticated with an Apify Proxy password (PROXY_PASSWORD or ACTOR_RUN_PROXY_PASSWORD) gets reduced data on both endpoints: only getPlan() (with just getAvailableProxyGroups()), getEffectivePlatformFeatures(), and getIsPaying() are set, and getId() and getUsername() are null.

User fields: getUsername(), getProfile() (UserProfile: getBio(), getReadme(), getName(), getPictureUrl(), getGithubUsername(), getWebsiteUrl(), getTwitterUsername(), all nullable). Private fields: getId(), getEmail(), getProxy() (UserProxy: getPassword(), getGroups() as List<ProxyGroup>, each with getName()/getDescription()/getAvailableCount() as Long), getPlan() (UserPlan: getId(), getDescription(), getIsEnabled(), getMonthlyBasePriceUsd()/getMonthlyUsageCreditsUsd()/getUsageDiscountPercent()/ getMaxMonthlyUsageUsd()/getMaxActorMemoryGbytes()/getMaxMonthlyActorComputeUnits()/ getMaxMonthlyResidentialProxyGbytes()/getMaxMonthlyProxySerps()/ getMaxMonthlyExternalDataTransferGbytes() as Double, getEnabledPlatformFeatures() as List<String>, getMaxActorCount()/getMaxActorTaskCount()/getDataRetentionDays()/ getTeamAccountSeatCount() as Long, getAvailableProxyGroups() as JsonNode, getSupportLevel(), getAvailableAddOns() as List<JsonNode>), getEffectivePlatformFeatures() (JsonNode), getCreatedAt() (Instant), getIsPaying() (Boolean). Plus getExtra(), a Map<String, Object> carrying any account field not modeled directly.

Logs: client.log(id)

Access a build's or run's log directly, or via client.run(id).log() / client.build(id).log().

Method Description
get() / get(LogOptions) The whole log as text. Completes with Optional<String> when addressed by an explicit id (client.log(id)); on run.log()/build.log() (no log id of its own), a 404 is ambiguous and throws NotFoundError instead; see Fetching single resources.
getAsBytes() / getAsBytes(LogOptions) As get(), but completes with Optional<byte[]> (the raw bytes, not decoded as text). Same 404 handling as get().
stream() / stream(LogOptions) A live InputStream over the log (for redirection). Completes with InputStream. The request is retried like any other, until the headers arrive; it throws on an error response that is not retried, or the last one once the retries run out, including a 404.

LogOptions fields: raw(Boolean), download(Boolean).

Optional<String> log = client.log("RUN_OR_BUILD_ID").get().join();
log.ifPresent(System.out::println);