Single and collection clients
The Apify client provides two types of resource clients: single-resource clients for managing an individual resource, and collection clients for listing or creating resources.
ActorClient- Manages a single resource.ActorCollectionClient- Manages a collection of resources.
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: 'MY-APIFY-TOKEN' });
// Collection clients don't take a parameter.
const actorCollectionClient = client.actors();
// Create an Actor with the name my-actor.
const myActor = await actorCollectionClient.create({ name: 'my-actor' });
// List your Actors, both your own and the ones from Apify Store you've used.
const { items } = await actorCollectionClient.list();
The resource ID can be the resource's id or a combination of username/resource-name.
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: 'MY-APIFY-TOKEN' });
// Resource clients take the ID of the resource.
const actorClient = client.actor('username/actor-name');
// Fetch the username/actor-name object from the API.
const myActor = await actorClient.get();
// Start a run of username/actor-name and return the run object.
const myActorRun = await actorClient.start();
Every API resource follows the same pattern: client.datasets() returns a collection client, and client.dataset(id) a client for one dataset.