Users¶
client.users: /api/v1/users/...
Bases: Resource
The users you can access: yourself, managed users you created, and people who shared.
A managed user is an account you created (create); it has no login of its own and
you manage its data. A shared user has their own account and granted you access, for
example an athlete you coach. list covers everyone; retrieve, update and
delete work on managed users only, as on the server.
create(*, first_name, last_name=None)
¶
Creates a managed user: an account without a login, managed by you.
Endpoint: POST /api/v1/users/
Parameters:
-
first_name(str) –First name.
-
last_name(str | None, default:None) –Last name.
Returns:
-
UserResponse(UserResponse) –The new user. Act as them with
client.delegated_client(user.id).
Raises:
-
SweatStackAuthError–If you may not create managed users.
-
SweatStackAPIError–If the API request fails for any other reason.
Examples:
from sweatstack import Client
client = Client()
junior = client.users.create(first_name="Bob", last_name="Smit")
junior_client = client.delegated_client(junior.id)
delete(user_id)
¶
Deletes a managed user and all their data. This cannot be undone.
Endpoint: DELETE /api/v1/users/{user_id}
Parameters:
-
user_id(str) –The managed user's ID.
Raises:
-
SweatStackNotFoundError–If the user does not exist or is not managed by you.
-
SweatStackAPIError–If the API request fails for any other reason.
Examples:
from sweatstack import Client
client = Client()
client.users.delete("usr_bob")
list(*, include_managed=True, include_shared=True, name=None)
¶
Lists the users you can access, yourself included.
Endpoint: GET /api/v1/users/
Always runs as the signed-in (principal) user, also on a delegated client, because the endpoint does not accept delegated tokens.
Parameters:
-
include_managed(bool, default:True) –Include managed users.
-
include_shared(bool, default:True) –Include users who shared access with you.
-
name(str | None, default:None) –Only users whose display name contains this, ignoring case. Returns every match, so check the length before picking one.
Returns:
-
list[UserSummary]–list[UserSummary]: The users, each with the
scopesyou hold for them.
Raises:
-
SweatStackAPIError–If the API request fails.
Examples:
from sweatstack import Client
client = Client()
matches = client.users.list(name="carla")
if len(matches) != 1:
raise ValueError(f"Expected one user matching 'carla', found {len(matches)}")
athlete = client.delegated_client(matches[0])
retrieve(user_id)
¶
Retrieves a managed user.
Endpoint: GET /api/v1/users/{user_id}
Only users you manage. For anyone else, yourself included, use :meth:list.
Parameters:
-
user_id(str) –The managed user's ID.
Returns:
-
UserResponse(UserResponse) –The user.
Raises:
-
SweatStackNotFoundError–If the user does not exist or is not managed by you.
-
SweatStackAPIError–If the API request fails for any other reason.
Examples:
from sweatstack import Client
client = Client()
print(client.users.retrieve("usr_bob").display_name)
update(user_id, *, first_name=None, last_name=None)
¶
Updates a managed user's name. Fields you leave out are unchanged.
Endpoint: PUT /api/v1/users/{user_id}
Parameters:
-
user_id(str) –The managed user's ID.
-
first_name(str | None, default:None) –The new first name.
-
last_name(str | None, default:None) –The new last name.
Returns:
-
UserResponse(UserResponse) –The updated user.
Raises:
-
SweatStackNotFoundError–If the user does not exist or is not managed by you.
-
SweatStackAPIError–If the API request fails for any other reason.
Examples:
from sweatstack import Client
client = Client()
client.users.update("usr_bob", last_name="de Vries")