Skip to main content
Version: Next

Convenience methods

The Apify client provides several convenience methods to handle actions that the API alone can't perform efficiently, such as waiting for an Actor run to finish without running into network timeouts:

  • ActorClient.call() - Starts an Actor and waits for it to finish, handling network timeouts internally. Waits indefinitely by default, or up to the specified waitSecs.
  • ActorClient.start() - Starts an Actor and immediately returns the run object. Its waitForFinish option asks the API to hold the response for up to 60 seconds.
  • RunClient.waitForFinish() - Waits for an already started run to reach a terminal status.

When waitSecs runs out before the run finishes, the returned promise resolves to a run object with status READY or RUNNING, which doesn't contain the Actor run output. Tasks have the same methods on TaskClient, and builds have BuildClient.waitForFinish().

import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'MY-APIFY-TOKEN' });

const actorClient = client.actor('username/actor-name');

// Start an Actor and wait for it to finish.
const finishedActorRun = await actorClient.call();

// Start an Actor and wait up to 60 seconds for it to finish.
const actorRun = await actorClient.start(undefined, { waitForFinish: 60 });

// Wait for an already started run to finish.
const finishedRun = await client.run(actorRun.id).waitForFinish();
tip

The call() method polls internally and may take a long time for long-running Actors. Use start() and waitForFinish() separately if you need more control over the waiting behavior.

Additionally, storage-related resources offer flexible options for data retrieval:

  • Key-value store records can be retrieved as parsed values, buffers, or streams.
  • Dataset items can be fetched as individual objects, iterated asynchronously, or downloaded as serialized data in formats such as CSV or XLSX.