Skip to main content
Version: Next

ApifyClient

The official JavaScript client for the Apify API.

Provides programmatic access to all Apify platform resources including Actors, runs, datasets, key-value stores, request queues, and more. Works in both Node.js and browser environments.

@example
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'my-token' });

// Start an Actor and wait for it to finish
const run = await client.actor('my-actor-id').call();

// Fetch dataset items
const { items } = await client.dataset(run.defaultDatasetId).listItems();
@see

Index

Constructors

constructor

Properties

baseUrl

baseUrl: string

httpClient

httpClient: HttpClient

logger

logger: Log

publicBaseUrl

publicBaseUrl: string

stats

stats: Statistics

optionaltoken

token?: string

Methods

actor

  • Returns a client for a specific Actor.

    Use this to get, update, delete, start, or call an Actor, as well as manage its builds, runs, versions, and webhooks.

    @see
    @example
    // Call an Actor and wait for it to finish
    const run = await client.actor('apify/web-scraper').call({ url: 'https://example.com' });

    Parameters

    • id: string

      Actor ID or username/name

    Returns ActorClient

    A client for the specific Actor

actors

build

builds

dataset

  • Returns a client for a specific dataset.

    Use this to read, write, and manage items in the dataset. Datasets contain structured data stored as individual items (records).

    @see
    @example
    // Push items to a dataset
    await client.dataset('my-dataset').pushItems([
    { url: 'https://example.com', title: 'Example' },
    { url: 'https://test.com', title: 'Test' }
    ]);

    // Retrieve items
    const { items } = await client.dataset('my-dataset').listItems();

    Parameters

    • id: string

      Dataset ID or name

    Returns DatasetClient<Data>

    A client for the specific Dataset

datasets

keyValueStore

  • Returns a client for a specific key-value store.

    Use this to read, write, and delete records in the store. Key-value stores can hold any type of data including text, JSON, images, and other files.

    @see
    @example
    // Save a record
    await client.keyValueStore('my-store').setRecord({ key: 'OUTPUT', value: { foo: 'bar' } });

    // Get a record
    const record = await client.keyValueStore('my-store').getRecord('OUTPUT');

    Parameters

    • id: string

      Key-value store ID or name

    Returns KeyValueStoreClient

    A client for the specific key-value store

keyValueStores

log

requestQueue

  • Returns a client for a specific request queue.

    Use this to add, retrieve, and manage requests in the queue. Request queues are used by web crawlers to manage URLs that need to be visited.

    @see
    @example
    // Add requests to a queue
    const queue = client.requestQueue('my-queue');
    await queue.addRequest({ url: 'https://example.com', uniqueKey: 'example' });

    // Get and lock the next request
    const { items } = await queue.listAndLockHead({ lockSecs: 60 });

    Parameters

    • id: string

      Request queue ID or name

    • options: RequestQueueUserOptions = {}

      Configuration options for the request queue client

    Returns RequestQueueClient

    A client for the specific Request queue

requestQueues

run

  • Returns a client for a specific Actor run.

    Use this to get details about a run, wait for it to finish, abort it, or access its dataset, key-value store, and request queue.

    @see
    @example
    // Wait for a run to finish
    const run = await client.run('run-id').waitForFinish();

    // Access run's dataset
    const { items } = await client.run('run-id').dataset().listItems();

    Parameters

    • id: string

      Run ID

    Returns RunClient

    A client for the specified run

runs

schedule

schedules

setStatusMessage

  • setStatusMessage(message, options): Promise<void>
  • Sets a status message for the current Actor run.

    This is a convenience method that updates the status message of the run specified by the ACTOR_RUN_ID environment variable. Only works when called from within an Actor run.

    @throws

    If ACTOR_RUN_ID environment variable is not set


    Parameters

    • message: string

      The status message to set

    • optionaloptions: SetStatusMessageOptions

      Additional options for the status message

    Returns Promise<void>

store

task

  • Returns a client for a specific Actor task.

    Use this to get, update, delete, or run a task with pre-configured input.

    @see
    @example
    // Run a task and wait for it to finish
    const run = await client.task('my-task').call();

    Parameters

    • id: string

      Task ID or username/task-name

    Returns TaskClient

    A client for the specified task

tasks

user

  • Returns a client for accessing user data.

    By default, returns information about the current user (determined by the API token).

    @see

    Parameters

    • id: string = ME_USER_NAME_PLACEHOLDER

      User ID or username. Defaults to 'me' (current user)

    Returns UserClient

    A client for the user

webhook

webhookDispatch

webhookDispatches

webhooks