Skip to content

Account provider

pythonxbox.api.provider.account.AccountProvider(client)

Bases: BaseProvider

Source code in src/pythonxbox/api/provider/baseprovider.py
def __init__(self, client: "XboxLiveClient") -> None:
    """
    Initialize an the BaseProvider

    Args:
        client (:class:`XboxLiveClient`): Instance of XboxLiveClient
    """
    self.client = client

BASE_URL_USER_MGT = 'https://user.mgt.xboxlive.com' class-attribute instance-attribute

BASE_URL_ACCOUNT = 'https://accounts.xboxlive.com' class-attribute instance-attribute

HEADERS_USER_MGT = {'x-xbl-contract-version': '1'} class-attribute instance-attribute

HEADERS_ACCOUNT = {'x-xbl-contract-version': '2'} class-attribute instance-attribute

claim_gamertag(xuid, gamertag, **kwargs) async

Claim gamertag

XLE error codes

400 - Bad API request 401 - Unauthorized 409 - Gamertag unavailable 429 - Too many requests 200 - Gamertag available

Parameters:

Name Type Description Default
xuid int

Your xuid as integer

required
gamertag str

Desired gamertag

required

Returns: ClaimGamertagResult

Source code in src/pythonxbox/api/provider/account/__init__.py
async def claim_gamertag(
    self, xuid: str, gamertag: str, **kwargs
) -> ClaimGamertagResult:
    """
    Claim gamertag

    XLE error codes:
        400 - Bad API request
        401 - Unauthorized
        409 - Gamertag unavailable
        429 - Too many requests
        200 - Gamertag available

    Args:
        xuid (int): Your xuid as integer
        gamertag (str): Desired gamertag

    Returns: ClaimGamertagResult
    """
    url = self.BASE_URL_USER_MGT + "/gamertags/reserve"
    post_data = {"Gamertag": gamertag, "ReservationId": str(xuid)}
    resp = await self.client.session.post(
        url, json=post_data, headers=self.HEADERS_USER_MGT, **kwargs
    )
    try:
        return ClaimGamertagResult(resp.status_code)
    except ValueError:
        resp.raise_for_status()

change_gamertag(xuid, gamertag, preview=False, **kwargs) async

Change your gamertag.

XLE error codes

200 - success 1020 - No free gamertag changes available

Parameters:

Name Type Description Default
xuid int

Your Xuid as integer

required
gamertag str

Desired gamertag name

required
preview bool

Preview the change

False

Returns: ChangeGamertagResult

Source code in src/pythonxbox/api/provider/account/__init__.py
async def change_gamertag(
    self, xuid: str, gamertag: str, preview: bool = False, **kwargs
) -> ChangeGamertagResult:
    """
    Change your gamertag.

    XLE error codes:
        200 - success
        1020 - No free gamertag changes available

    Args:
        xuid (int): Your Xuid as integer
        gamertag (str): Desired gamertag name
        preview (bool): Preview the change

    Returns: ChangeGamertagResult
    """
    url = self.BASE_URL_ACCOUNT + "/users/current/profile/gamertag"
    post_data = {
        "gamertag": gamertag,
        "preview": preview,
        "reservationId": int(xuid),
    }
    resp = await self.client.session.post(
        url, json=post_data, headers=self.HEADERS_ACCOUNT, **kwargs
    )
    try:
        return ChangeGamertagResult(resp.status_code)
    except ValueError:
        resp.raise_for_status()