Visitar URL original
TypeScript SDK - Introduction
Skip to main content
View the TypeScript SDK GitHub repository for the latest installation instructions, examples, and source code.
Build strongly typed scraping workflows for search engines, eCommerce platforms, social media, AI tools, and more with the official Decodo TypeScript SDK.
  • Fully typed targets and parameters with IDE autocomplete
  • Sync, async, and batch scraping methods
  • Web search, site mapping, and crawling through the Web Data API
  • Native fetch support; requires Node.js 18 or later
  • Typed error hierarchy for safer integrations

What is the Decodo TypeScript SDK?

The Decodo TypeScript SDK provides a typed interface for interacting with Decodo targets like Google, Amazon, TikTok, YouTube, ChatGPT, Perplexity, and more. Instead of manually constructing HTTP requests and validating payloads, you work with fully typed methods and target-specific parameters directly in your editor.

Why use the SDK?

  • Strong typing and autocomplete – target parameters are fully typed for better editor support and fewer mistakes.
  • Unified scraping interface – work with search engines, eCommerce platforms, social media, and AI tools through one SDK.
  • Async and batch workflows – create scraping tasks, poll task status, and process batches at scale.
  • Typed errors – handle authentication, validation, timeout, and rate-limit failures safely.
  • Minimal setup – uses native fetch, no additional HTTP client required.

Requirements

  • Node.js 18 or later, for native fetch
  • TypeScript 5.0 or later, recommended for best type inference

Installation

Quick start

Create a new project:
npm init -y creates a CommonJS package, so a file using import fails with SyntaxError: Cannot use import statement outside a module. Switch the package to ES modules first:
Copy your Web Data API key from your Web Data API subscription on the Decodo dashboard. Keep it out of your source by storing it in an environment variable:
Older plans only have a basic authentication token. Pass it as token instead of apiKey – see Configuration.
Then create main.js and initialize the client:
Run the script:
Keep the file plain JavaScript. TypeScript-only syntax such as the non-null assertion in process.env.DECODO_API_KEY! is a SyntaxError: Unexpected token '!' under node main.js. Use that form only in a .ts file you compile or run through a TypeScript loader.

Configuration

Pass either apiKey or token, never both:
Setting both throws webScrapingApi accepts either token or apiKey, not both. Provide only one. Setting neither throws webScrapingApi requires apiKey or token in DecodoConfig. An invalid baseUrl throws webScrapingApi baseUrl must be a valid URL.Which credential you pass also decides which API the SDK calls. An apiKey uses the Web Data API at data.decodo.com, which is the only way to reach search, map, and crawl. A token uses the older Web Scraping API at scraper-api.decodo.com, which supports scraping only.

Scraping

Access the API via client.webScrapingApi. The examples below assume Target is already imported, along with DecodoClient where needed:

Sync scrape

Waits for the scraping result before returning:

Async scrape

Creates a scraping task and returns immediately. Poll separately for task status and results:

Batch scrape

Send multiple queries or URLs in a single request:

Web Data API: search, map, and crawl

These methods are served by the Web Data API at data.decodo.com and require an apiKey. Calling one on a client configured with a basic authentication token throws before any request is sent, for example: search() requires webScrapingApi.apiKey. A Basic token cannot call the Data API. Runs a web search and returns the results page:

Map

Discovers the links on a site:

Crawl

crawl() starts a crawl, polls its status, and returns every page once it settles:
The status returned here is the full status object, not a string - the state itself is status.status. A check like if (status === 'done') never matches. The object also carries crawl_id, discovered, completed, failed, and in_flight.
To drive a crawl step by step, start it and poll separately for status and pages:
For large crawls, listCrawlPages() returns one cursor-paged batch at a time. Pass the next value back as cursor until it is empty:

Supported targets

Each target accepts one primary input parameter (url, query, product_id, or prompt) together with optional configuration.

Search engines

eCommerce

Social media

AI tools

Other

Universal and raw URL scraping

Twelve targets predate the current API schema. The Decodo SDKs generate from a shared schema; the TypeScript SDK currently ships the v2.1.1 target set, while the Python and Go SDKs are on v2.3.0. The twelve targets below exist only in the TypeScript SDK:ecommerce, google_maps, google_shopping_product, google_shopping_search, google_suggest, google_trends_explore, instagram_graphql_profile, lowes_search, universal_ecommerce, youtube_search_max, youtube_transcript, youtube_videoMost of them still work. Three do not, and currently return an error: google_suggest, youtube_video, and google_shopping_product. Avoid these three in new code. If you need Google Shopping data, google_shopping_search works.
Target.UniversalEcommerce isn’t included in the tables because it doesn’t accept a primary input parameter such as url, query, product_id, or prompt. It only accepts optional configuration fields such as callback_url.
For the full target list and parameter details, see Target list and Parameters.

Error handling

The SDK throws typed errors that map to API error codes:
AuthenticationError, RateLimitError, and ValidationError extend DecodoError. TimeoutError sits outside the DecodoError hierarchy, so handle it separately.
  • CLI – Run Decodo scraping workflows from the command line.
  • Python SDK – Integrate the Decodo APIs into Python projects.
  • Go SDK – Integrate the Decodo APIs into Go projects.
  • MCP Server – Connect AI agents and MCP-compatible tools to Decodo.
  • GitHub repository – View the TypeScript SDK source code, examples, and latest releases.

Support

Need help or just want to say hello? Our support is available 24/7.
You can also reach us anytime via email at support@decodo.com.

Feedback

Can’t find what you’re looking for? Request an article!
Have feedback? Share your thoughts on how we can improve.