Skip to main content
Version: 3.2

Call actor

This example demonstrates how to start an Apify actor using and how to call the Apify API using Actor.newClient(). The script gets a random weird word and its explanation from and sends it to your email using the apify/send-mail actor.

To make the example work, you'll need an Apify account. Go to the Settings - Integrations page to obtain your API token and set it to the APIFY_TOKEN environment variable, or run the script using the Apify CLI. If you deploy this actor to the Apify Cloud, you can do things like set up a scheduler to run your actor early in the morning.

To see what other actors are available, visit the Apify Store.

To run this example on Apify Platform, use the apify/actor-node-puppeteer-chrome image for your Dockerfile.

import { Actor } from 'apify';
import { launchPuppeteer } from 'crawlee';

await Actor.init();

// Launch the web browser.
const browser = await launchPuppeteer();

console.log('Obtaining own email address...');
const apifyClient = Actor.newClient();
const { email } = await apifyClient.user().get();

// Load and get a random word
console.log('Fetching a random word.');
const page = await browser.newPage();
await page.goto('');
const randomWord = await page.$eval('#shared_section', (el) => el.outerHTML);

// Send random word to your email. For that, you can use an actor we already
// have available on the platform under the name: apify/send-mail.
// The second parameter to the invocation is the actor's
// desired input. You can find the required input parameters by checking
// the actor's documentation page:
console.log(`Sending email to ${}...`);
await'apify/send-mail', {
to: email,
subject: 'Random Word',
html: `<h1>Random Word</h1>${randomWord}`,
console.log('Email sent. Good luck!');

// Close Browser
await browser.close();

await Actor.exit();