Nested clients
Nested clients let you access related resources directly from a parent resource client, without manually constructing new client instances. For example, the runs of an Actor are available from its client.
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: 'MY-APIFY-TOKEN' });
const actorClient = client.actor('username/actor-name');
const runsClient = actorClient.runs();
// List the last 10 runs of the Actor.
const { items: runs } = await runsClient.list({ limit: 10, desc: true });
// Select the last run of the Actor that finished with a SUCCEEDED status.
const lastSucceededRunClient = actorClient.lastRun({ status: 'SUCCEEDED' });
// Fetch items from the run's dataset.
const { items } = await lastSucceededRunClient.dataset().listItems();
This direct access to the dataset (and other storage resources) from the RunClient is especially convenient when used alongside the ActorClient.lastRun() method.