apify-sdk-integration

โดย apify

รวม Apify เข้ากับแอปพลิเคชัน JavaScript/TypeScript หรือ Python ที่มีอยู่โดยใช้แพ็คเกจ apify-client ใช้เมื่อเพิ่มการขูดเว็บ ระบบอัตโนมัติ หรือข้อมูล...

npx skills add https://github.com/apify/apify-claude-code-plugin --skill apify-sdk-integration

Apify SDK Integration

Add Apify Actor execution to an existing application. This skill covers the apify-client package for JS/TS and Python, plus the REST API for other languages.

When to Use This Skill

  • Adding web scraping or automation to an existing app
  • Calling Apify Actors programmatically from application code
  • Building a product that uses Apify as a backend service
  • Integrating Actor results into a data pipeline

Critical: Package Naming

apify-client is the API client for calling Actors from your app. apify is the SDK for building Actors (wrong package for this use case).

Always install apify-client. Never install apify for integration work.

Prerequisites

The user needs an APIFY_TOKEN. Direct them to Console > Settings > Integrations at https://console.apify.com/settings/integrations to create one. If they don't have an account: https://console.apify.com/sign-up (free, no credit card).

Store the token securely — environment variable or secrets manager, never hardcoded.

Finding the Right Actor

Before writing integration code, find the Actor that fits the user's needs. Use the MCP tools if available:

  • search-actors — search the Apify Store by keyword
  • fetch-actor-details — get the Actor's input schema, output format, and pricing

Alternatively, browse https://apify.com/store. Append .md to any Actor's Store URL to get its docs in markdown.

JavaScript / TypeScript

Install

npm install apify-client

Synchronous Execution (wait for results)

import { ApifyClient } from 'apify-client';

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

const run = await client.actor('apify/web-scraper').call({
    startUrls: [{ url: 'https://example.com' }],
    maxPagesPerCrawl: 10,
});

const { items } = await client.dataset(run.defaultDatasetId).listItems();

.call() blocks until the Actor finishes. Use for short-running Actors (under a few minutes).

Asynchronous Execution (start and poll/retrieve later)

const run = await client.actor('apify/web-scraper').start({
    startUrls: [{ url: 'https://example.com' }],
});

// Poll for completion
const finishedRun = await client.run(run.id).waitForFinish();

// Retrieve results
const { items } = await client.dataset(finishedRun.defaultDatasetId).listItems();

Use .start() + .waitForFinish() for long-running Actors or when you need the run ID immediately.

Retrieving Results

// Dataset items (structured data from pushData)
const { items } = await client.dataset(run.defaultDatasetId).listItems({
    limit: 100,
    offset: 0,
});

// Key-value store (files, screenshots, etc.)
const record = await client.keyValueStore(run.defaultKeyValueStoreId).getRecord('OUTPUT');

Error Handling

try {
    const run = await client.actor('apify/web-scraper').call(input);

    if (run.status !== 'SUCCEEDED') {
        const log = await client.log(run.id).get();
        throw new Error(`Actor failed with status ${run.status}: ${log}`);
    }

    const { items } = await client.dataset(run.defaultDatasetId).listItems();
} catch (error) {
    if (error.message?.includes('not found')) {
        // Actor ID is wrong or Actor was deleted
    } else if (error.statusCode === 401) {
        // Invalid or missing APIFY_TOKEN
    }
    throw error;
}

Python

Install

pip install apify-client

Synchronous Execution

from apify_client import ApifyClient
import os

client = ApifyClient(token=os.environ['APIFY_TOKEN'])

run = client.actor('apify/web-scraper').call(run_input={
    'startUrls': [{'url': 'https://example.com'}],
    'maxPagesPerCrawl': 10,
})

items = client.dataset(run['defaultDatasetId']).list_items().items

Asynchronous Execution

run = client.actor('apify/web-scraper').start(run_input={
    'startUrls': [{'url': 'https://example.com'}],
})

# Poll for completion
finished_run = client.run(run['id']).wait_for_finish()

items = client.dataset(finished_run['defaultDatasetId']).list_items().items

Async Client (asyncio)

from apify_client import ApifyClientAsync

client = ApifyClientAsync(token=os.environ['APIFY_TOKEN'])

run = await client.actor('apify/web-scraper').call(run_input={
    'startUrls': [{'url': 'https://example.com'}],
})

items = (await client.dataset(run['defaultDatasetId']).list_items()).items

REST API (Any Language)

For languages without an official client, use the REST API directly.

Start a Run

POST https://api.apify.com/v2/acts/{actorId}/runs
Authorization: Bearer <APIFY_TOKEN>
Content-Type: application/json

{ "startUrls": [{ "url": "https://example.com" }] }

Get Run Status

GET https://api.apify.com/v2/acts/{actorId}/runs/{runId}
Authorization: Bearer <APIFY_TOKEN>

Get Dataset Items

GET https://api.apify.com/v2/datasets/{datasetId}/items?format=json
Authorization: Bearer <APIFY_TOKEN>

Full API reference: https://docs.apify.com/api/v2

Best Practices

  • Set timeouts: Pass timeoutSecs in the Actor input or use waitSecs on .call() to avoid indefinite waits.
  • Paginate large datasets: Use limit and offset when retrieving dataset items. Default limit is 250K items.
  • Reuse clients: Create one ApifyClient instance and reuse it across calls.
  • Handle Actor-specific input: Every Actor has its own input schema. Use fetch-actor-details MCP tool or append .md to the Actor's Store URL to get the schema before constructing input.

Documentation

If the Apify MCP server is available, use search-apify-docs and fetch-apify-docs tools for contextual documentation lookups during development.

Skills เพิ่มเติมจาก apify

bug-triage
apify
จัดลำดับความสำคัญของปัญหาบั๊กที่เปิดอยู่ใน apify/apify-mcp-server วิเคราะห์ ร่างคำตอบ ขออนุมัติ แล้วโพสต์
official
apify-influencer-brand-collabs
apify
Discover Instagram brand–creator partnerships by chaining Apify Actors. Use when the user asks who collabs with a brand, which brands a creator has done paid…
official
dig
apify
ทักษะที่ยืดหยุ่นสำหรับการสำรวจ วางแผน และกำหนดขอบเขตงานบนเซิร์ฟเวอร์ Apify MCP ห้ามแก้ไขไฟล์ต้นฉบับ — ทักษะนี้ใช้เพื่อการทำความเข้าใจและวางแผนเท่านั้น
official
apify-financial-news
apify
ค้นหาและดึงข่าวการเงินสำหรับบริษัทในพอร์ตที่ติดตามจาก 33 แหล่งข่าวระดับ Tier 1 ที่ได้รับการยืนยัน (Bloomberg, Reuters, FT, WSJ, IntelliNews, ČTK, PAP, BTA,…
official
apify-actor-development
apify
สร้าง, ดีบัก, และปรับใช้โปรแกรมคลาวด์แบบไร้เซิร์ฟเวอร์สำหรับการขูดเว็บ, ระบบอัตโนมัติ, และการประมวลผลข้อมูล รองรับเทมเพลต JavaScript, TypeScript, และ Python พร้อมไลบรารี Crawlee, Playwright, และ Cheerio ในตัวสำหรับการรวบรวมข้อมูลผ่าน HTTP และเบราว์เซอร์ รวมถึงการทดสอบในเครื่องผ่าน apify run พร้อมพื้นที่จัดเก็บแบบแยกส่วน, การตรวจสอบความถูกต้องของสคีมาสำหรับอินพุต/เอาต์พุต, และการปรับใช้ไปยังแพลตฟอร์ม Apify ผ่าน apify push ต้องมีการรับรองความถูกต้องของ Apify CLI และข้อมูลเมตา generatedBy ที่จำเป็นใน .actor/actor.json สำหรับ AI...
official
apify-actorization
apify
แปลงโปรเจกต์ที่มีอยู่ให้เป็น Apify Actors แบบไร้เซิร์ฟเวอร์ พร้อมการผสานรวม SDK เฉพาะภาษา รองรับ JavaScript/TypeScript (ด้วย Actor.init() / Actor.exit()), Python (ตัวจัดการบริบทแบบอะซิงก์) และภาษาอื่นๆ ผ่าน CLI wrapper มีเวิร์กโฟลว์ที่มีโครงสร้าง: apify init เพื่อสร้างโครงร่าง, ใช้ SDK wrapping, กำหนดค่า schemas อินพุต/เอาต์พุต, ทดสอบในเครื่องด้วย apify run, จากนั้นปรับใช้ด้วย apify push รวมถึงการตรวจสอบความถูกต้องของ schema อินพุตและเอาต์พุต, การทำ Docker containerization, และตัวเลือกการจ่ายต่อเหตุการณ์...
official
apify-generate-output-schema
apify
สร้างสคีมาเอาต์พุต (dataset_schema.json, output_schema.json, key_value_store_schema.json) สำหรับ Apify Actor โดยการวิเคราะห์ซอร์สโค้ดของมัน ใช้เมื่อ...
official
apify-ultimate-scraper
apify
เว็บสแครปเปอร์อัตโนมัติที่เลือก Actor ที่เหมาะสมที่สุดสำหรับ 55+ แพลตฟอร์ม รวมถึง Instagram, TikTok, YouTube, Facebook, Google Maps และอื่นๆ ครอบคลุม Actor ที่กำหนดค่าไว้ล่วงหน้ากว่า 55 ตัวใน 8 แพลตฟอร์มหลัก พร้อมคำแนะนำการเลือกตามกรณีการใช้งานเฉพาะ (การสร้างลีด, การค้นหาอินฟลูเอนเซอร์, การตรวจสอบแบรนด์, การวิเคราะห์คู่แข่ง, การวิจัยเทรนด์) รองรับรูปแบบเอาต์พุตสามแบบ: การแสดงผลแชทด่วน, การส่งออก CSV หรือการส่งออก JSON พร้อมขีดจำกัดผลลัพธ์ที่ปรับแต่งได้ รวมถึงรูปแบบเวิร์กโฟลว์แบบหลาย Actor สำหรับการทำงานที่ซับซ้อน...
official