# Watchlog: SDKs

Official client libraries for the Watchlog REST API, open source (MIT) on GitHub: https://github.com/watchlogdev. Every client reads the API key from `WATCHLOG_API_KEY` and sends it as a Bearer token. Human-readable page: https://www.watchlog.dev/docs/sdks

## Install

| SDK | Install | Repository |
| --- | --- | --- |
| Node.js / TypeScript | `npm install @watchlogdev/sdk` | https://github.com/watchlogdev/watchlog-node |
| Python | `pip install watchlogdev` | https://github.com/watchlogdev/watchlog-python |
| Go | `go get github.com/watchlogdev/watchlog-go` | https://github.com/watchlogdev/watchlog-go |
| Java | Not on Maven Central: build it from its repository with Maven. | https://github.com/watchlogdev/watchlog-java |
| .NET | `dotnet add package Watchlog` | https://github.com/watchlogdev/watchlog-dotnet |
| Ruby | `gem install watchlogdev` | https://github.com/watchlogdev/watchlog-ruby |
| PHP | `composer require watchlogdev/sdk` | https://github.com/watchlogdev/watchlog-php |
| CLI | `npm install -g @watchlogdev/cli` | https://github.com/watchlogdev/watchlog-cli |
| MCP server | `npx -y @watchlogdev/mcp` | https://github.com/watchlogdev/watchlog-mcp |

## Quick start (Node.js)

```js
import { WatchlogClient } from "@watchlogdev/sdk";

// Reads your API key from WATCHLOG_API_KEY.
const client = new WatchlogClient();

// Track a watch and get its first price.
const { data: product } = await client.trackProduct({
  product: "id49860660",
  wait: true,
});
console.log(product.title, product.price, product.currency);

// Its price history, oldest first.
const { data: tracked } = await client.getProduct({ id: product.product_id, days: 90 });
for (const point of tracked.history) console.log(point.checked_at, point.price);

// Any reference's history, tracked or not, without using credits.
const { data: history } = await client.getWatchHistory({ watch_id: "126610LN" });
console.log(history.lowest_price, history.highest_price);
```

## Quick start (Python)

```python
from watchlog import WatchlogClient

# Reads your API key from WATCHLOG_API_KEY.
with WatchlogClient() as client:
    # Track a watch and get its first price.
    product = client.track_product(product="id49860660", wait=True).data
    print(product["title"], product["price"], product["currency"])

    # Its price history, oldest first.
    tracked = client.get_product(id=product["product_id"], days=90).data
    for point in tracked["history"]:
        print(point["checked_at"], point["price"])

    # Any reference's history, tracked or not, without using credits.
    history = client.get_watch_history(watch_id="126610LN").data
    print(history["lowest_price"], history["highest_price"])
```

## Methods

One method per endpoint, with the API's parameter names. Java and PHP use the Node.js names, Go the same in PascalCase, .NET in PascalCase with Async, and Ruby the Python names.

| Node.js | Python | Endpoint | Does |
| --- | --- | --- | --- |
| `getAccount` | `get_account` | `GET /account` | Plan and remaining credits |
| `searchWatches` | `search_watches` | `GET /search` | Search watches |
| `getWatchHistory` | `get_watch_history` | `GET /history` | Price history of any watch |
| `listProducts` | `list_products` | `GET /products` | List tracked products |
| `trackProduct` | `track_product` | `POST /products` | Track a watch |
| `getProduct` | `get_product` | `GET /products/{id}` | Get a product and its price history |
| `updateProduct` | `update_product` | `PATCH /products/{id}` | Change alerts and checks |
| `checkProduct` | `check_product` | `POST /products/{id}/check` | Check the price now |
| `deleteProduct` | `delete_product` | `DELETE /products/{id}` | Stop tracking a product |
| `clearTargetPrice` | `clear_target_price` | `PATCH /products/{id}` | Remove a product's target price |

## Errors and retries

A failed request throws an error with the HTTP status and the API's error code, such as api_limit or product_limit: WatchlogApiError (status, errorCode) in Node.js, WatchlogAPIError (status, error_code) in Python. Network errors and 408, 500, 502, 503 and 504 answers are retried up to 3 times; 429 and other errors aren't, since rate limits last until the hour is over.
