---
name: apify-hello-world
description: |-
  Run your first Apify Actor and retrieve results via apify-client.
  Use when starting a new Apify integration, testing connectivity,
  or learning the Actor call/dataset retrieval pattern.
  Trigger with "apify hello world", "apify example", "run an apify actor",
  "apify quick start", "first apify scrape".
allowed-tools: Read, Write, Edit, Bash(npm:*), Bash(npx:*), Bash(node:*)
version: 1.5.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - scraping
  - automation
  - apify
compatibility: Designed for Claude Code
title: apify-hello-world
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/apify-hello-world
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-hello-world/references/examples.md), [references/patterns.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-hello-world/references/patterns.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/apify-hello-world`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/apify-hello-world`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/apify-hello-world) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/apify-hello-world`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/apify-hello-world --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/apify-hello-world --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Apify Hello World

## Overview

Run a public Actor from the Apify Store, wait for it to finish, and retrieve the scraped data. This demonstrates the fundamental call-wait-collect pattern used in every Apify integration.

## Prerequisites

- `npm install apify-client` completed
- `APIFY_TOKEN` environment variable set
- See `apify-install-auth` if not ready

## Authentication

Every call authenticates with a personal API token passed to the client
constructor: `new ApifyClient({ token: process.env.APIFY_TOKEN })`. Keep the
token in the `APIFY_TOKEN` environment variable — never hard-code it in the
script. Full setup (where to generate the token, how to export it) lives in the
`apify-install-auth` skill.

## Core Pattern: Call Actor, Get Data

```typescript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });

// 1. Run an Actor and wait for it to finish
const run = await client.actor('apify/website-content-crawler').call({
  startUrls: [{ url: 'https://docs.apify.com/academy' }],
  maxCrawlPages: 5,
});

// 2. Retrieve results from the default dataset
const { items } = await client.dataset(run.defaultDatasetId).listItems();

console.log(`Crawled ${items.length} pages:`);
items.forEach(item => {
  console.log(`  - ${item.url}: ${item.text?.substring(0, 80)}...`);
});
```

This is the whole workflow at a high level: authenticate, `.call()` an Actor,
then read its default dataset. For sync-vs-async execution, pagination,
downloads, key-value store retrieval, run-configuration options, and a table of
popular starter Actors, see [run & retrieval patterns](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-hello-world/references/patterns.md).

## Instructions

### Step 1: Create the Script

Use Write (or Edit an existing file) to create `hello-apify.ts` (or `.js`) with
the Core Pattern code above. Use Read to confirm the file contents before running.

### Step 2: Run It

```bash
# With tsx (recommended)
npx tsx hello-apify.ts

# Or with Node.js (plain JS)
node hello-apify.js
```

### Step 3: Understand the Output

The Actor runs on Apify's cloud infrastructure. See the Output section below for
the run-object fields returned when it finishes.

## Output

A successful run returns a run object plus a populated dataset. The fields you
read most:

| Field | Meaning |
|-------|---------|
| `run.id` | Unique run identifier |
| `run.status` | `SUCCEEDED`, `FAILED`, `TIMED-OUT`, or `ABORTED` |
| `run.defaultDatasetId` | ID of the dataset containing scrape results |
| `run.defaultKeyValueStoreId` | ID of the KV store with metadata/artifacts |
| `run.statusMessage` | Human-readable detail (essential when status is not `SUCCEEDED`) |

`client.dataset(run.defaultDatasetId).listItems()` returns `{ items }`, where
each item is one scraped record (shape depends on the Actor). Always branch on
`run.status` before reading the dataset — a `FAILED` run can leave an empty or
partial dataset. See [worked examples](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-hello-world/references/examples.md) for the full
run-object breakdown.

## Error Handling

| Error | Cause | Solution |
|-------|-------|----------|
| `Actor not found` | Wrong Actor ID | Check ID at apify.com/store |
| `run.status === 'FAILED'` | Actor crashed | Check `run.statusMessage` for details |
| `run.status === 'TIMED-OUT'` | Exceeded timeout | Increase `timeout` or reduce workload |
| `Dataset is empty` | Actor produced no output | Verify input parameters; check Actor logs |
| `402 Payment Required` | Insufficient compute units — Apify returns HTTP 402 when your account is out of prepaid units | Top up at console.apify.com/billing |

## Examples

Minimal happy-path collection — call an Actor and count the results:

```typescript
const run = await client.actor('apify/website-content-crawler').call({
  startUrls: [{ url: 'https://example.com' }],
  maxCrawlPages: 10,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(`Scraped ${items.length} pages`);
```

For the complete status-guarded "scrape and save to JSON" script and a full
breakdown of the run object, see [worked examples](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-hello-world/references/examples.md).

## Resources

- [Apify Store — Browse Actors](https://apify.com/store)
- [Run Actor via API](https://docs.apify.com/academy/api/run-actor-and-retrieve-data-via-api)
- [JS Client Examples](https://docs.apify.com/api/client/js/docs/guides/examples)
- [Run & retrieval patterns](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-hello-world/references/patterns.md) — sync/async, pagination, run config, starter Actors
- [Worked examples](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/apify-hello-world/references/examples.md) — full scrape-and-save script

## Next Steps

Once your first Actor run succeeds, proceed to the `apify-local-dev-loop` skill
to build and iterate on your own Actor locally, then deploy it back to the Apify
platform. That skill covers the develop-run-debug cycle in depth.
