Skip to content

Wyze API Methods

The following functions use the Wyze REST APIs to fetch the required set of data needed to authenticate with cameras locally.

login(email, password, phone_id=None)

Authenticate with Wyze

This method calls out to the /user/login endpoint of auth-prod.api.wyze.com (using https), and retrieves an access token necessary to retrieve other information from the wyze server.

Parameters:

Name Type Description Default
email str

Email address used to log into wyze account

required
password str

Password used to log into wyze account. This is used to authenticate with the wyze API server, and return a credential.

required
phone_id Optional[str]

the ID of the device to emulate when talking to wyze. This is safe to leave as None (in which case a random phone id will be generated)

None

Returns:

Type Description
WyzeCredential

a WyzeCredential with the access information, suitable for passing to get_user_info(), or get_camera_list().

Source code in wyzecam/api.py
def login(
    email: str, password: str, phone_id: Optional[str] = None
) -> WyzeCredential:
    """Authenticate with Wyze

    This method calls out to the `/user/login` endpoint of
    `auth-prod.api.wyze.com` (using https), and retrieves an access token
    necessary to retrieve other information from the wyze server.

    :param email: Email address used to log into wyze account
    :param password: Password used to log into wyze account.  This is used to
                     authenticate with the wyze API server, and return a credential.
    :param phone_id: the ID of the device to emulate when talking to wyze.  This is
                     safe to leave as None (in which case a random phone id will be
                     generated)

    :returns: a [WyzeCredential][wyzecam.api.WyzeCredential] with the access information, suitable
              for passing to [get_user_info()][wyzecam.api.get_user_info], or
              [get_camera_list()][wyzecam.api.get_camera_list].
    """
    if phone_id is None:
        phone_id = str(uuid.uuid4())

    payload = {"email": email, "password": triplemd5(password)}
    resp = requests.post(
        "https://auth-prod.api.wyze.com/user/login",
        json=payload,
        headers=get_headers(phone_id),
    )
    resp.raise_for_status()

    return WyzeCredential.parse_obj(dict(resp.json(), phone_id=phone_id))

get_user_info(auth_info)

Gets Wyze Account Information

This method calls out to the /app/user/get_user_info endpoint of api.wyze.com (using https), and retrieves the account details of the authenticated user.

Parameters:

Name Type Description Default
auth_info WyzeCredential

the result of a login() call.

required

Returns:

Type Description
WyzeAccount

a WyzeAccount with the user's info, suitable for passing to WyzeIOTC.connect_and_auth().

Source code in wyzecam/api.py
def get_user_info(auth_info: WyzeCredential) -> WyzeAccount:
    """Gets Wyze Account Information

    This method calls out to the `/app/user/get_user_info`
    endpoint of `api.wyze.com` (using https), and retrieves the
    account details of the authenticated user.

    :param auth_info: the result of a [`login()`][wyzecam.api.login] call.
    :returns: a [WyzeAccount][wyzecam.api.WyzeAccount] with the user's info, suitable
          for passing to [`WyzeIOTC.connect_and_auth()`][wyzecam.iotc.WyzeIOTC.connect_and_auth].

    """
    payload = _get_payload(auth_info.access_token, auth_info.phone_id)
    ui_headers = get_headers(auth_info.phone_id, SCALE_USER_AGENT)
    resp = requests.post(
        "https://api.wyzecam.com/app/user/get_user_info",
        json=payload,
        headers=ui_headers,
    )
    resp.raise_for_status()

    resp_json = resp.json()
    assert resp_json["code"] == "1", "Call failed"

    return WyzeAccount.parse_obj(
        dict(resp_json["data"], phone_id=auth_info.phone_id)
    )

get_camera_list(auth_info)

Source code in wyzecam/api.py
def get_camera_list(auth_info: WyzeCredential) -> List[WyzeCamera]:
    data = get_homepage_object_list(auth_info)
    result = []
    for device in data["device_list"]:  # type: Dict[str, Any]
        if device["product_type"] != "Camera":
            continue

        device_params = device.get("device_params", {})
        p2p_id: Optional[str] = device_params.get("p2p_id")
        p2p_type: Optional[int] = device_params.get("p2p_type")
        ip: Optional[str] = device_params.get("ip")
        enr: Optional[str] = device.get("enr")
        mac: Optional[str] = device.get("mac")
        product_model: Optional[str] = device.get("product_model")
        nickname: Optional[str] = device.get("nickname")
        timezone_name: Optional[str] = device.get("timezone_name")

        if not p2p_id:
            continue
        if not p2p_type:
            continue
        if not ip:
            continue
        if not enr:
            continue
        if not mac:
            continue
        if not product_model:
            continue

        result.append(
            WyzeCamera(
                p2p_id=p2p_id,
                p2p_type=p2p_type,
                ip=ip,
                enr=enr,
                mac=mac,
                product_model=product_model,
                nickname=nickname,
                timezone_name=timezone_name,
            )
        )
    return result