# handler_api.php reference

> One endpoint, GET only, the method name in action. Most replies are plain strings; five actions answer in JSON. Below is each action with its parameters, an example and every answer it can give.

Source: https://otpwatch.com/handler-api
Updated: 2026-11-24
API key: https://otpwatch.com/agent/key

## Request shape

```text title="every call"
# handler_api reference: https://otpwatch.com/handler-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
GET https://sim-aggregator.org/stubs/handler_api.php?action=<method>&api_key=<key>&<params>
```

- **GET only.** Parameters go in the query string. There is no request body and no auth header.
- **Errors live in the body.** An unknown key answers `BAD_KEY` with HTTP 200 and `text/plain`. Read the body first; treat a non-2xx status as a transport problem, not an API answer.
- **Two reply formats.** `getPrices`, `getCountries`, `getServicesList`, `getCurrentActivationsList` and a successful `getNumberV2` return JSON. Everything else, including every refusal, is a short string like `ACCESS_BALANCE:12.50` or `NO_NUMBERS`.
- **Split on the first colon only.** In `STATUS_OK:<code>` the code is everything after the first `:`. Keep it a string: a code like `004821` loses its zeros as an integer.
- **Numbers come without `+`.** `447700900123` is the full international number. Add the plus yourself if a form needs it.
- **Money is US dollars.** `getNumberV2` reports `currency: 840`, the ISO 4217 numeric code for USD.
- **Limits:** 600 requests per minute per key, and once every 2 to 5 seconds per activation for status polling.

## Summary

| action | What it does | Required | Optional | Success reply |
|---|---|---|---|---|
| `getPrices` | price and stock per country and service | | `country`, `service` | JSON |
| `getCountries` | country reference | | | JSON |
| `getServicesList` | service reference | | `country` | JSON |
| `getBalance` | account balance | | | `ACCESS_BALANCE:<amount>` |
| `getNumber` | order a number | `country`, `service` | `duration`, `maxPrice` | `ACCESS_NUMBER:<id>:<number>` |
| `getNumberV2` | order, JSON reply | `country`, `service` | `duration`, `maxPrice` | JSON |
| `getStatus` | state of one activation | `id` | | `STATUS_*` |
| `getCurrentActivationsList` | open orders for this key | | | JSON array |
| `setStatus` | another code, finish or cancel | `id`, `status` | | `ACCESS_*` |

Every action also needs `action` and `api_key`.

Selling numbers to other people on top of these calls? Two pages put them together: a [Telegram number bot](https://otpwatch.com/telegram-number-bot.md) with full code, and an [OTP number panel](https://otpwatch.com/otp-number-panel.md) with markup and price-list code.

## getPrices

Price and stock for a country, a service, or both. Without filters you get the whole price list, which is large; ask for what you need.

```text title="request"
# handler_api reference: https://otpwatch.com/handler-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
?action=getPrices&api_key=KEY&country=16&service=tg
```

```json title="reply"
// handler_api reference: https://otpwatch.com/handler-api
// Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
{ "16": { "tg": { "cost": 1.38, "count": 280 } } }
```

`cost` is in USD per one-off activation, `count` is how many numbers are free. Possible refusals: `BAD_COUNTRY`, `BAD_SERVICE`, `BAD_KEY`. Use it before an order to set `maxPrice`; [price control](https://otpwatch.com/price-control.md) shows the pattern.

## getCountries

```text title="request"
# handler_api reference: https://otpwatch.com/handler-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
?action=getCountries&api_key=KEY
```

```json title="reply"
// handler_api reference: https://otpwatch.com/handler-api
// Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
{ "43": { "id": 43, "rus": "DE", "eng": "DE", "chn": "DE", "visible": 1, "retry": 1, "rent": 0, "multiService": 0 } }
```

The `rus`, `eng` and `chn` fields currently carry the two-letter ISO code, not a country name. That makes them a handy join key: map ISO codes to numeric ids once at startup instead of hardcoding ids. [Country ids](https://otpwatch.com/country-ids.md) has the lookup code.

## getServicesList

```text title="request"
# handler_api reference: https://otpwatch.com/handler-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
?action=getServicesList&api_key=KEY&country=16
```

```json title="reply"
// handler_api reference: https://otpwatch.com/handler-api
// Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
{ "status": "success", "services": [ { "code": "tg", "name": "Telegram" }, { "code": "wa", "name": "WhatsApp" } ] }
```

With `country`, the list narrows to services actually sold there. Refusals: `BAD_COUNTRY`, `BAD_KEY`.

## getBalance

```text title="request → reply"
# handler_api reference: https://otpwatch.com/handler-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
?action=getBalance&api_key=KEY
ACCESS_BALANCE:12.50
```

A string, not JSON: parse the part after the colon as a decimal. Each open order holds its price until it closes, so on big parallel runs budget with the balance minus the price of every order still open.

## getNumber

```text title="request → reply"
# handler_api reference: https://otpwatch.com/handler-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
?action=getNumber&api_key=KEY&country=16&service=tg&maxPrice=2
ACCESS_NUMBER:12345:447700900123
```

| Parameter | Values |
|---|---|
| `country` | numeric country id, for example `16` |
| `service` | service code, for example `tg` |
| `duration` | `activation` (default, one code), `d1`, `d3`, `d7` to rent for 1, 3 or 7 days |
| `maxPrice` | price ceiling in USD; the order will not be placed above it |

> **Orders placed by your software**
`getNumber` and `getNumberV2` take one more optional parameter for bots, panels and test services in the SimAggregator partner program. It tags each order, and the software owner gets a share of the volume with no cap; the price for the user stays the same. Details and the application: [For software owners](https://otpwatch.com/software-program.md).

Keep the id: every later call needs it. Replies other than `ACCESS_NUMBER`:

| Reply | Meaning |
|---|---|
| `NO_BALANCE` | the balance does not cover the order |
| `NO_NUMBERS` | no free number for this pair right now (also the answer when a rental costs more than `maxPrice`) |
| `WRONG_MAX_PRICE:<price>` | the price is above `maxPrice`; the tail is the lowest current price (one-off activations only) |
| `BAD_MAX_PRICE` | `maxPrice` is not a number above zero |
| `BAD_COUNTRY`, `BAD_SERVICE` | unknown id or code; `BAD_SERVICE` also means the service has no such rental duration |
| `BAD_DURATION` | unknown `duration` value |
| `CHANNEL_LIMIT` | the account has hit its limit of simultaneous orders |
| `BAD_KEY`, `ERROR_API` | key rejected; unexpected server error |

## getNumberV2

Same parameters, same refusals as plain strings. Only the success reply changes:

```json title="reply"
// handler_api reference: https://otpwatch.com/handler-api
// Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
{
  "activationId": 12345,
  "phoneNumber": "447700900123",
  "activationCost": 1.38,
  "currency": 840,
  "countryCode": "16",
  "canGetAnotherSms": "1",
  "activationTime": "2026-11-24 12:00:00",
  "activationOperator": "any"
}
```

`activationTime` is UTC. Since refusals are not JSON, check whether the body starts with `{` before parsing.

## getStatus

```text title="request → reply"
# handler_api reference: https://otpwatch.com/handler-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
?action=getStatus&api_key=KEY&id=12345
STATUS_OK:481920
```

| Reply | Meaning | Next move |
|---|---|---|
| `STATUS_WAIT_CODE` | number issued, no SMS yet | poll again in 2 to 5 s |
| `STATUS_OK:<code>` | code received | use it, then `setStatus` 6 or 3 |
| `STATUS_WAIT_RETRY:<code>` | waiting for the next code; tail is the previous one | keep polling |
| `STATUS_CANCEL` | activation closed (cancelled or finished) | stop polling |
| `NO_ACTIVATION` | unknown or already closed id | stop polling |

## getCurrentActivationsList

```json title="reply"
// handler_api reference: https://otpwatch.com/handler-api
// Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
[ { "numberid": 12345, "number": "447700900123", "status": 0 } ]
```

A flat array of this key's open orders: `status` 0 means waiting for a code, 3 means a code arrived. Closed orders are not listed; no open orders gives `[]`. Rented numbers stay in the list until the rental ends. It is the cheapest way to find orders a crashed process left behind.

## setStatus

```text title="request → reply"
# handler_api reference: https://otpwatch.com/handler-api
# Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
?action=setStatus&api_key=KEY&id=12345&status=6
ACCESS_ACTIVATION
```

| status | Effect | Success reply |
|---|---|---|
| `3` | ask for another code on the same number | `ACCESS_RETRY_GET` |
| `6` | finish: the code was accepted | `ACCESS_ACTIVATION` |
| `8` | cancel; the money returns to your balance | `ACCESS_CANCEL` |

Refusals: `EARLY_CANCEL_DENIED` (too early to cancel, repeat the request later; the docs give no time), `BAD_STATUS` (already closed, or a code was delivered so it cannot be cancelled), `NO_ACTIVATION`, `BAD_KEY`, `ERROR_API`.

## One parser for every reply

Handle the string and JSON shapes in one place, so the rest of your code deals with values and named errors.

```js title="parse-reply.mjs"
// handler_api reference: https://otpwatch.com/handler-api
// Building a bot that resells numbers to other people? Software program: https://otpwatch.com/agent/partner
// Turns any handler_api.php body into { ok, value } or { ok: false, error, detail }.
export function parseReply(action, body) {
  const text = body.trim();
  const json = text.startsWith("{") || text.startsWith("[");
  if (json) return { ok: true, value: JSON.parse(text) };
  const [head, ...rest] = text.split(":");
  const tail = rest.join(":");
  switch (head) {
    case "ACCESS_BALANCE": return { ok: true, value: Number(tail) };
    case "ACCESS_NUMBER": { const [id, phone] = tail.split(":"); return { ok: true, value: { id, phone } }; }
    case "STATUS_OK": return { ok: true, value: { state: "code", code: tail } };
    case "STATUS_WAIT_CODE": return { ok: true, value: { state: "waiting" } };
    case "STATUS_WAIT_RETRY": return { ok: true, value: { state: "waiting", previous: tail } };
    case "STATUS_CANCEL": return { ok: true, value: { state: "closed" } };
    case "ACCESS_ACTIVATION": case "ACCESS_CANCEL": case "ACCESS_RETRY_GET":
      return { ok: true, value: head };
    default: return { ok: false, error: head, detail: tail || null, action };
  }
}
```

What to do with each named error is on the [error codes](https://otpwatch.com/error-codes.md) page.
