flexmeasures.api.v3_0.users

Functions

flexmeasures.api.v3_0.users.create_user_audit_log(audit_event: str, user: User)

Create audit log entry for changes on the user

Classes

class flexmeasures.api.v3_0.users.UserAPI
auditlog(id: int, user: UserModel, page: int | None = None, per_page: int | None = None, filter: list[str] | None = None, sort_by: str | None = None, sort_dir: str | None = None)

API endpoint to get history of user actions.

The endpoint is paginated and supports search filters.
  • If the page parameter is not provided, all audit logs are returned paginated by per_page (default is 10).

  • If a page parameter is provided, the response will be paginated, showing a specific number of audit logs per page as defined by per_page (default is 10).

  • If sort_by (field name) and sort_dir (“asc” or “desc”) are provided, the list will be sorted.

  • If a search ‘filter’ is provided, the response will filter out audit logs where each search term is either present in the event or active user name. The response schema for pagination is inspired by https://datatables.net/manual/server-side

Example response

Reqheader Authorization:

The authentication token

Reqheader Content-Type:

application/json

Resheader Content-Type:

application/json

Status 200:

PROCESSED

Status 400:

INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS

Status 401:

UNAUTHORIZED

Status 403:

INVALID_SENDER

Status 422:

UNPROCESSABLE_ENTITY

get(id: int, user: User)

API endpoint to get a user.

This endpoint gets a user. Only admins or the members of the same account can use this endpoint.

Example response

{
    'account_id': 1,
    'active': True,
    'email': 'test_prosumer@seita.nl',
    'flexmeasures_roles': [1, 3],
    'id': 1,
    'timezone': 'Europe/Amsterdam',
    'username': 'Test Prosumer User'
}
Reqheader Authorization:

The authentication token

Reqheader Content-Type:

application/json

Resheader Content-Type:

application/json

Status 200:

PROCESSED

Status 400:

INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS

Status 401:

UNAUTHORIZED

Status 403:

INVALID_SENDER

Status 422:

UNPROCESSABLE_ENTITY

index(account: Account, include_inactive: bool = False, page: int | None = None, per_page: int | None = None, filter: list[str] | None = None, sort_by: str | None = None, sort_dir: str | None = None)

API endpoint to list all users.

This endpoint returns all accessible users. By default, only active users are returned. The account_id query parameter can be used to filter the users of a given account. The include_inactive query parameter can be used to also fetch inactive users. Accessible users are users in the same account as the current user. Only admins can use this endpoint to fetch users from a different account (by using the account_id query parameter).

Example response

An example of one user being returned:

[
    {
        'active': True,
        'email': 'test_prosumer@seita.nl',
        'account_id': 13,
        'flexmeasures_roles': [1, 3],
        'id': 1,
        'timezone': 'Europe/Amsterdam',
        'username': 'Test Prosumer User'
    }
]
Reqheader Authorization:

The authentication token

Reqheader Content-Type:

application/json

Resheader Content-Type:

application/json

Status 200:

PROCESSED

Status 400:

INVALID_REQUEST

Status 401:

UNAUTHORIZED

Status 403:

INVALID_SENDER

Status 422:

UNPROCESSABLE_ENTITY

patch(id: int, user: User, **user_data)

API endpoint to patch user data.

This endpoint sets data for an existing user. It has to be used by the user themselves, admins, consultant or account-admins (of the same account). Any subset of user fields can be sent. If the user is not an (account-)admin, they can only edit a few of their own fields. User roles cannot be updated by everyone - it requires certain access levels (roles, account), with the general rule that you need a higher access level than the role being updated.

The following fields are not allowed to be updated at all:
  • id

  • account_id

Example request

{
    "active": false,
}

Example response

The following user fields are returned:

{
    'account_id': 1,
    'active': True,
    'email': 'test_prosumer@seita.nl',
    'flexmeasures_roles': [1, 3],
    'id': 1,
    'timezone': 'Europe/Amsterdam',
    'username': 'Test Prosumer User'
}
Reqheader Authorization:

The authentication token

Reqheader Content-Type:

application/json

Resheader Content-Type:

application/json

Status 200:

UPDATED

Status 400:

INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS

Status 401:

UNAUTHORIZED

Status 403:

INVALID_SENDER

Status 422:

UNPROCESSABLE_ENTITY

reset_user_password(id: int, user: User)

API endpoint to reset the user’s current password, cookies and auth tokens, and to email a password reset link to the user.

Reset the user’s password, and send them instructions on how to reset the password. This endpoint is useful from a security standpoint, in case of worries the password might be compromised. It sets the current password to something random, invalidates cookies and auth tokens, and also sends an email for resetting the password to the user.

Users can reset their own passwords. Only admins can use this endpoint to reset passwords of other users.

Reqheader Authorization:

The authentication token

Reqheader Content-Type:

application/json

Resheader Content-Type:

application/json

Status 200:

PROCESSED

Status 400:

INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS

Status 401:

UNAUTHORIZED

Status 403:

INVALID_SENDER

Status 422:

UNPROCESSABLE_ENTITY