Sign up and contact support to get 100 free checks.Sign up free
WA Lookup workflow illustration for the article “WhatsApp Number Checker API in Python”
A visual overview of the workflow discussed in this WA Lookup article.

How do you check if a number is on WhatsApp in Python?

POST a JSON body with service_type set to ws and identifier set to an E.164 number to https://api.walookup.com/api/v1/check, sending your key in the X-API-Key header. If the response code is 0, data.registered is the answer. Code 42200 means undetermined and is not charged; 42901 means wait for Retry-After and resend. No WhatsApp login or phone session is needed.

To check whether a number is on WhatsApp from Python, send one HTTPS request to the WA Lookup API with the number in E.164 format and read data.registered from the JSON response. The answer comes back in the same response, and you never log in to WhatsApp or automate a phone session. The code below uses requests, handles every documented outcome, and extends to up to 100 numbers per call.

What do you need before writing code?

  • An API key. Create one in your WA Lookup dashboard under Settings and expose it to the process as an environment variable, here WA_LOOKUP_API_KEY. Keep it out of source control and client-side code.
  • Balance. Each completed check is charged; see the pricing page. After registering you can contact support to request the standard trial credit.
  • Numbers in E.164 form: country code plus national number, for example +12345678900 (see ITU-T E.164). The leading + is optional; the server normalises it. Do not guess a missing country code.
  • Python 3.9+ and requests (pip install requests).

How do you check one number?

import os
import sys
import time

import requests

API = "https://api.walookup.com/api/v1"
RETRY_CODES = {42901, 50303, 50400}  # documented as not charged


def check_number(number: str, service_type: str = "ws", attempts: int = 3) -> dict:
    headers = {"X-API-Key": os.environ["WA_LOOKUP_API_KEY"]}
    payload = {"service_type": service_type, "identifier": number}

    for attempt in range(1, attempts + 1):
        try:
            resp = requests.post(f"{API}/check", json=payload, headers=headers, timeout=70)
        except requests.RequestException as exc:
            return {"state": "request_error", "detail": str(exc)}
        try:
            body = resp.json()
        except ValueError:  # e.g. a proxy error page instead of JSON
            return {"state": "http_error", "http_status": resp.status_code}

        code = body.get("code")
        if code == 0 and isinstance(body.get("data"), dict):
            return {"state": "completed", "data": body["data"]}
        if code == 42200:
            return {"state": "undetermined"}
        if code in RETRY_CODES and attempt < attempts:
            time.sleep(float(resp.headers.get("Retry-After") or 2))
            continue
        return {"state": "api_error", "http_status": resp.status_code, "code": code}


if __name__ == "__main__":
    if len(sys.argv) != 2:
        raise SystemExit("usage: python check.py +12345678900")
    print(check_number(sys.argv[1]))

requests sets Content-Type: application/json when you pass json=. The 70-second client timeout sits just above the API's 60-second limit for a single check, so the server's own timeout code (50400) arrives before your client gives up.

A completed check prints:

{'state': 'completed', 'data': {'service_type': 'ws', 'identifier': '+12345678900', 'registered': True}}

The state values are labels in this script, not API fields. The API's envelope is code, msg and data; the answer is data.registered, and False is a real, completed negative.

How should each response code be handled?

Read the business code in the JSON body rather than relying on the HTTP status alone:

code Meaning Charged Script behaviour
0 Completed; data.registered is true or false Yes Return the data
42200 (HTTP 422) Could not be determined; no data No Return undetermined; retry later, never store as false
42901 Five requests already in flight, or a multi check already running No Sleep for Retry-After, resend
50303 Service at capacity No Sleep for Retry-After, resend
50400 Timed out No Resend
40002 Invalid number — Fix the input
40100 / 40200 Bad API key / insufficient balance — Stop and alert

Keep these states apart in your database. A timeout or a 42200 converted into registered = False silently pushes reachable contacts into the wrong segment.

How do you check other fields, such as Business or activity?

Pass a different service_type. The response keeps service_type, identifier and registered and adds the product's fields:

result = check_number("+12345678900", service_type="ws_business")
if result["state"] == "completed":
    data = result["data"]
    print(data["registered"], data.get("business"))
service_type Extra fields
ws_avatar avatar, avatar_url (empty string when no URL is available)
ws_profile avatar, avatar_url, estimated category, age (may be absent), gender, skin_color, hair_color
ws_business business
ws_active activedays (days since last activity; None in Python when not registered)

Use data.get(...) for optional fields such as age. business == False does not mean the number is personal, and activedays is a day count, not a last-seen time.

How do you check up to 100 numbers in one call?

The synchronous multi endpoint takes an identifiers list and answers in one response, in the same order:

def check_many(numbers: list[str], service_type: str = "ws") -> list[dict]:
    if len(numbers) > 100:
        raise ValueError("send at most 100 numbers per multi check")
    resp = requests.post(
        f"{API}/batch-check",
        json={"service_type": service_type, "identifiers": numbers},
        headers={"X-API-Key": os.environ["WA_LOOKUP_API_KEY"]},
        timeout=320,
    )
    body = resp.json()
    if body.get("code") != 0:
        raise RuntimeError(f"multi check not completed, code={body.get('code')}")

    rows = []
    for item in body["data"]["results"]:
        if item["exists"]:
            rows.append({"identifier": item["identifier"], "state": "completed",
                         "registered": item["registered"]})
        else:
            rows.append({"identifier": item["identifier"], "state": "no_result"})
    return rows

exists: false means that number produced no result (invalid format, undetermined or failed), and the other fields are absent. Retry those rows rather than marking them unregistered. Only one multi check per account runs at a time, so send batches one after another, not in parallel. The 320-second timeout covers the API's 300-second limit; if that limit is hit, the whole request fails and is refunded.

For files far larger than this, use the asynchronous bulk task instead of looping thousands of single calls: upload a TXT or CSV file, poll the task and download the result file. The bulk registration check page and the API documentation describe that flow.

What should a production integration add?

  • Log the source record reference and check time with each state, never the API key.
  • Deduplicate numbers before checking. If several records share a number, check it once and map the result back.
  • Append, don't overwrite. Store each check as a new dated row so an error never replaces an earlier completed result.
  • Respect the concurrency limit. At most five requests in flight per account; a thread pool of five or fewer avoids most 42901 responses.
  • Keep scope clear. A completed result describes account presence at check time. It does not send a message, read chats, or prove identity, consent or deliverability.

FAQ

Can I use urllib instead of requests?

Yes. The request is a plain HTTPS POST with a JSON body and an X-API-Key header, so urllib.request works the same way. With urllib, a 422 response raises HTTPError; read its body to get code 42200.

Is a "not registered" answer charged?

Yes. Any completed check is charged, true or false. Undetermined (42200), capacity (50303), concurrency (42901) and timeout (50400) responses are not.

Do I need a WhatsApp account or a linked phone?

No. The API runs the check on WA Lookup's side. Your code only needs the API key.

Is there an async version for asyncio?

The API itself is synchronous per request. You can call it from httpx.AsyncClient or aiohttp with the same body and headers, keeping no more than five requests in flight.

Sources