> ## Documentation Index
> Fetch the complete documentation index at: https://help.decodo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> The official TypeScript SDK for the Decodo APIs, with strongly typed targets, IDE autocomplete, and sync, async, and batch scraping methods.

> [!NOTE]
>
> View the [TypeScript SDK GitHub repository](https://github.com/Decodo/sdk-ts) 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

```bash theme={null}
npm install --save @decodo/sdk-ts
```

## Quick start

Create a new project:

```bash theme={null}
mkdir scrape-with-decodo
cd scrape-with-decodo
npm init -y
npm install --save @decodo/sdk-ts
touch main.js
```

`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:

```bash theme={null}
node -e "let p=require('./package.json'); p.type='module'; require('fs').writeFileSync('./package.json', JSON.stringify(p, null, 2))"
```

Copy your Web Data API key from your Web Data API subscription on the [**Decodo dashboard**](https://dashboard.decodo.com/web-data/playground). Keep it out of your source by storing it in an environment variable:

```bash theme={null}
export DECODO_API_KEY=your_api_key
```

> [!NOTE]
>
> Older plans only have a basic authentication token. Pass it as `token` instead of `apiKey` – see [Configuration](#configuration).

Then create `main.js` and initialize the client:

```javascript theme={null}
// main.js
import { DecodoClient, Target } from '@decodo/sdk-ts';

const client = new DecodoClient({
  webScrapingApi: {
    apiKey: process.env.DECODO_API_KEY,
  },
});

const result = await client.webScrapingApi.scrape({
  target: Target.GoogleSearch,
  query: 'coffee shops',
  geo: 'United States',
  parse: true,
});

console.log(JSON.stringify(result, null, 2));
```

Run the script:

```bash theme={null}
node main.js
```

> [!WARNING]
>
> 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

```typescript theme={null}
const client = new DecodoClient({
  webScrapingApi: {
    apiKey: '<api_key>',
  },
  timeoutMs: 120_000, // optional, request timeout in ms (default: 180000)
});
```

Pass either `apiKey` or `token`, never both:

```typescript theme={null}
// Basic authentication token (older plans)
const client = new DecodoClient({
  webScrapingApi: {
    token: '<basic_auth_token>',
  },
});
```

| Parameter | Description |
| - | - |
| `apiKey` | Web Data API key from your subscription on the dashboard. **Recommended** |
| `token` | Basic authentication token for older plans. Use it instead of `apiKey` |
| `baseUrl` | Override the API base URL. Must be a valid URL |
| `timeoutMs` | Request timeout in milliseconds (default: 180000) |

> [!NOTE]
>
> 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](#web-data-api-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:

```typescript theme={null}
import { DecodoClient, Target } from '@decodo/sdk-ts';
```

### Sync scrape

Waits for the scraping result before returning:

```typescript theme={null}
const result = await client.webScrapingApi.scrape({
  target: Target.AmazonProduct,
  query: 'B09H74FXNW',
  parse: true,
});
```

### Async scrape

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

```typescript theme={null}
const task = await client.webScrapingApi.scrapeAsync({
  target: Target.GoogleSearch,
  query: 'laptop reviews',
  parse: true,
});

const meta = await client.webScrapingApi.getStatus(task.id);
console.log(meta.status); // 'pending' | 'done' | 'faulted'

const results = await client.webScrapingApi.getResults(task.id);
```

### Batch scrape

Send multiple queries or URLs in a single request:

```typescript theme={null}
const batch = await client.webScrapingApi.scrapeBatch({
  target: Target.GoogleSearch,
  query: ['coffee', 'tea', 'juice'],
  parse: true,
});

const coffeeTaskId = batch.queries[0].id;
await client.webScrapingApi.getResults(coffeeTaskId);
```

## 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.`

### Search

Runs a web search and returns the results page:

```typescript theme={null}
const serp = await client.webScrapingApi.search({
  query: 'laptop reviews',
  geo: 'United States',
});
```

### Map

Discovers the links on a site:

```typescript theme={null}
const map = await client.webScrapingApi.map({
  url: 'https://example.com',
  limit: 100,
});

const links = map.results[0].content.links;
```

### Crawl

`crawl()` starts a crawl, polls its status, and returns every page once it settles:

```typescript theme={null}
const { status, pages } = await client.webScrapingApi.crawl(
  { url: 'https://example.com', limit: 50, output: 'markdown' },
  { pollInterval: 5_000, timeout: 600_000 },
);

console.log(status.status, status.completed, status.failed); // 'done' 12 0
```

> [!WARNING]
>
> 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:

```typescript theme={null}
const job = await client.webScrapingApi.startCrawl({ url: 'https://example.com' });

const progress = await client.webScrapingApi.getCrawlStatus(job.crawl_id);
console.log(progress.status); // 'pending' | 'done' | 'faulted' | 'cancelled' | 'truncated'

const pages = await client.webScrapingApi.getCrawlResults(job.crawl_id);

await client.webScrapingApi.cancelCrawl(job.crawl_id);
```

For large crawls, `listCrawlPages()` returns one cursor-paged batch at a time. Pass the `next` value back as `cursor` until it is empty:

```typescript theme={null}
let cursor;

do {
  const page = await client.webScrapingApi.listCrawlPages(job.crawl_id, { cursor });
  for (const p of page.pages) console.log(p.url, p.status);
  cursor = page.next;
} while (cursor);
```

| Method | Description |
| - | - |
| `search(params)` | Run a web search and return the results page |
| `map(params)` | List the links on a site without fetching their content |
| `crawl(params, options)` | Start a crawl, wait for it, and return `{ status, pages }` |
| `startCrawl(params)` | Start a crawl and return its `crawl_id` immediately |
| `getCrawlStatus(crawlId)` | Report progress and the current status |
| `getCrawlResults(crawlId)` | Fetch every crawled page |
| `listCrawlPages(crawlId, options)` | Fetch one cursor-paged batch: `{ pages, next, total }` |
| `cancelCrawl(crawlId)` | Stop a running crawl |

## Supported targets

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

### Search engines

| Target | Description | Example |
| - | - | - |
| `Target.GoogleSearch` | Google Search results for a query | `{ target: Target.GoogleSearch, query: "coffee shops" }` |
| `Target.GoogleMaps` | Google Maps search results | `{ target: Target.GoogleMaps, query: "coffee shops brooklyn" }` |
| `Target.GoogleShoppingSearch` | Google Shopping search results | `{ target: Target.GoogleShoppingSearch, query: "laptop" }` |
| `Target.GoogleShoppingProduct` | Google Shopping product page. **Currently returns an error** – see the note below | `{ target: Target.GoogleShoppingProduct, query: "laptop" }` |
| `Target.GoogleSuggest` | Google Autocomplete suggestions. **Currently returns an error** – see the note below | `{ target: Target.GoogleSuggest, query: "coffee" }` |
| `Target.GoogleLens` | Google Lens reverse image search | `{ target: Target.GoogleLens, query: "https://example.com/cat.jpg" }` |
| `Target.GoogleAds` | Google Ads results for a query | `{ target: Target.GoogleAds, query: "laptop" }` |
| `Target.GoogleTravelHotels` | Google Travel hotel listings | `{ target: Target.GoogleTravelHotels, query: "hotels in paris" }` |
| `Target.GoogleTrendsExplore` | Google Trends Explore data | `{ target: Target.GoogleTrendsExplore, query: "web scraping" }` |
| `Target.BingSearch` | Bing Search results | `{ target: Target.BingSearch, query: "electric vehicles" }` |

### eCommerce

| Target | Description | Example |
| - | - | - |
| `Target.AmazonProduct` | Amazon product detail page by ASIN | `{ target: Target.AmazonProduct, query: "B09H74FXNW" }` |
| `Target.AmazonSearch` | Amazon search results | `{ target: Target.AmazonSearch, query: "laptop" }` |
| `Target.AmazonPricing` | Amazon pricing and offers | `{ target: Target.AmazonPricing, query: "B09H74FXNW" }` |
| `Target.AmazonSellers` | Amazon seller listings | `{ target: Target.AmazonSellers, query: "A1R0Z7FJGTKESH" }` |
| `Target.AmazonBestsellers` | Amazon bestsellers by category | `{ target: Target.AmazonBestsellers, query: "electronics" }` |
| `Target.WalmartProduct` | Walmart product page by product ID | `{ target: Target.WalmartProduct, product_id: "15296401808" }` |
| `Target.WalmartSearch` | Walmart search results | `{ target: Target.WalmartSearch, query: "laptop" }` |
| `Target.TargetProduct` | Target.com product page by product ID | `{ target: Target.TargetProduct, product_id: "92186007" }` |
| `Target.TargetSearch` | Target.com search results | `{ target: Target.TargetSearch, query: "laptop" }` |
| `Target.LowesSearch` | Lowe's search results | `{ target: Target.LowesSearch, query: "drill" }` |
| `Target.Ecommerce` | Generic eCommerce page with parser | `{ target: Target.Ecommerce, url: "https://example.com/product/123" }` |

### Social media

| Target | Description | Example |
| - | - | - |
| `Target.YoutubeVideo` | YouTube video by ID. **Currently returns an error** – see the note below | `{ target: Target.YoutubeVideo, query: "dFu9aKJoqGg" }` |
| `Target.YoutubeSearch` | YouTube search results | `{ target: Target.YoutubeSearch, query: "ambient music" }` |
| `Target.YoutubeSearchMax` | YouTube search results, extended result set | `{ target: Target.YoutubeSearchMax, query: "ambient music" }` |
| `Target.YoutubeMetadata` | YouTube video metadata by ID | `{ target: Target.YoutubeMetadata, query: "dFu9aKJoqGg" }` |
| `Target.YoutubeSubtitles` | YouTube video subtitles by ID | `{ target: Target.YoutubeSubtitles, query: "dFu9aKJoqGg" }` |
| `Target.YoutubeTranscript` | YouTube video transcript by ID. `language_code` is required | `{ target: Target.YoutubeTranscript, query: "dFu9aKJoqGg", language_code: "en" }` |
| `Target.YoutubeChannel` | YouTube channel by handle or ID | `{ target: Target.YoutubeChannel, query: "@decodo_official" }` |
| `Target.TiktokPost` | TikTok post by URL | `{ target: Target.TiktokPost, url: "https://www.tiktok.com/@nba/video/..." }` |
| `Target.TiktokShopSearch` | TikTok Shop search results | `{ target: Target.TiktokShopSearch, query: "wireless earbuds" }` |
| `Target.TiktokShopProduct` | TikTok Shop product page by product ID | `{ target: Target.TiktokShopProduct, product_id: "7100000000000000000" }` |
| `Target.InstagramGraphqlProfile` | Instagram profile by username | `{ target: Target.InstagramGraphqlProfile, query: "decodo_official" }` |

### AI tools

| Target | Description | Example |
| - | - | - |
| `Target.Chatgpt` | ChatGPT response for a prompt | `{ target: Target.Chatgpt, prompt: "What are the top three dog breeds?" }` |
| `Target.Perplexity` | Perplexity response for a prompt | `{ target: Target.Perplexity, prompt: "What causes seasonal allergies?" }` |
| `Target.Gemini` | Gemini response for a prompt | `{ target: Target.Gemini, prompt: "What are the top three dog breeds?" }` |
| `Target.GoogleAiMode` | Google AI Mode response | `{ target: Target.GoogleAiMode, query: "What are the top three dog breeds?" }` |

### Other

| Target | Description | Example |
| - | - | - |
| `Target.Bbb` | Better Business Bureau listing by URL | `{ target: Target.Bbb, url: "https://bbb.org/us/ny/new-york/..." }` |
| `Target.Autotrader` | Autotrader listing by URL | `{ target: Target.Autotrader, url: "https://autotrader.com/cars-for-sale/..." }` |
| `Target.Mobile` | Mobile.de listing by URL | `{ target: Target.Mobile, url: "https://mobile.de/auto/..." }` |
| `Target.AppleAppStore` | Apple App Store app by URL | `{ target: Target.AppleAppStore, url: "https://apps.apple.com/app/id12345" }` |
| `Target.Airbnb` | Airbnb listing by URL | `{ target: Target.Airbnb, url: "https://airbnb.com/rooms/12345" }` |

### Universal and raw URL scraping

| Target | Description | Example |
| - | - | - |
| `Target.Universal` | Any URL via the universal scraper | `{ target: Target.Universal, url: "https://example.com" }` |
| `Target.Google` | Raw Google URL scraping | `{ target: Target.Google, url: "https://google.com/search?q=laptop" }` |
| `Target.Bing` | Raw Bing URL scraping | `{ target: Target.Bing, url: "https://bing.com/search?q=laptop" }` |
| `Target.Amazon` | Raw Amazon URL scraping | `{ target: Target.Amazon, url: "https://amazon.com/dp/B09H74FXNW" }` |
| `Target.Walmart` | Raw Walmart URL scraping | `{ target: Target.Walmart, url: "https://walmart.com/ip/15296401808" }` |
| `Target.Target` | Raw Target.com URL scraping | `{ target: Target.Target, url: "https://target.com/p/-/A-92186007" }` |
| `Target.Tiktok` | Raw TikTok URL scraping | `{ target: Target.Tiktok, url: "https://www.tiktok.com/@nba" }` |

> [!WARNING]
>
> **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**](https://help.decodo.com/docs/python-sdk.md) and [**Go**](https://help.decodo.com/docs/go-sdk.md) 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_video`
>
> Most 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.

> [!NOTE]
>
> `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**](https://help.decodo.com/docs/web-scraping-api-targets.md) and [**Parameters**](https://help.decodo.com/docs/web-scraping-api-parameters-overview.md).

## Error handling

The SDK throws typed errors that map to API error codes:

```typescript theme={null}
import {
  DecodoError,
  AuthenticationError,
  RateLimitError,
  ValidationError,
  TimeoutError,
  Target,
} from '@decodo/sdk-ts';

try {
  await client.webScrapingApi.scrape({
    target: Target.GoogleSearch,
    query: 'test',
    parse: true,
  });
} catch (err) {
  if (err instanceof AuthenticationError) {
    // 401/403 - bad credentials
  } else if (err instanceof RateLimitError) {
    // 429 - too many requests
  } else if (err instanceof ValidationError) {
    // 422 - invalid parameters
    console.log(err.errors);
  } else if (err instanceof TimeoutError) {
    // request timed out
  }
}
```

`AuthenticationError`, `RateLimitError`, and `ValidationError` extend `DecodoError`. `TimeoutError` sits outside the `DecodoError` hierarchy, so handle it separately.

***

## Related

* [**CLI**](https://help.decodo.com/docs/cli.md) – Run Decodo scraping workflows from the command line.
* [**Python SDK**](https://help.decodo.com/docs/python-sdk.md) – Integrate the Decodo APIs into Python projects.
* [**Go SDK**](https://help.decodo.com/docs/go-sdk.md) – Integrate the Decodo APIs into Go projects.
* [**MCP Server**](https://help.decodo.com/docs/mcp.md) – Connect AI agents and MCP-compatible tools to Decodo.
* [GitHub repository ](https://github.com/Decodo/sdk-ts)– View the TypeScript SDK source code, examples, and latest releases.

***

> [card] [Support](https://direct.lc.chat/12092754)
>
> 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](mailto:support@decodo.com).

> [card] [Feedback](mailto:feedback@decodo.com)
>
> Can't find what you're looking for? Request an article! \
> Have feedback? Share your thoughts on how we can improve.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.