NAME

WebService::Mattermost::V4::API::Resource::User - Wrapped API methods for the users API endpoints.

VERSION

version 0.29

DESCRIPTION

API methods relating to a single user by ID.

USAGE

use WebService::Mattermost;

my $mm = WebService::Mattermost->new({
    authenticate => 1,
    username     => 'me@somewhere.com',
    password     => 'hunter2',
    base_url     => 'https://my.mattermost.server.com/api/v4/',
});

my $resource = $mm->api->user;

Optionally, you can set a global user ID for the resource and not pass the ID to every method:

$resource->id('USER-ID-HERE');

METHODS

All of the below methods can either be called as documented under each item, or from a user result object:

my $user = $resource->get('USER-ID-HERE')->item;

# Calls method "teams"
my $response = $user->call('teams');

# Calls method "update"
$response = $user->call('update', {
    # parameters
});
get()

Get a user

Get a user by their ID.

my $response = $resource->get('USER-ID-HERE');
update()

Update a user

Update a user by their ID.

my $response = $resource->update('USER-ID-HERE', {
    # Optional arguments
    email        => '...',
    username     => '...',
    first_name   => '...',
    last_name    => '...',
    nickname     => '...',
    locale       => '...',
    position     => '...',
    props        => {
        # ...
    },
    notify_props => {
        email         => \1,
        push          => \1,
        desktop       => \1,
        desktop_sound => \1,
        mention_keys  => \1,
        channel       => \1,
        first_name    => \1,
    },
});
teams()

Get a user's teams

deactivate()

Deactivate a user account

Set a user as inactive by ID.

$response->deactivate('USER-ID-HERE');
patch()

Patch a user

my $response = $resource->patch('USER-ID-HERE', {
    # Optional parameters:
    email        => '...',
    username     => '...',
    first_name   => '...',
    last_name    => '...',
    nickname     => '...',
    locale       => '...',
    position     => '...',
    props        => {
        # ...
    },
    notify_props => {
        email         => \1,
        push          => \1,
        desktop       => \1,
        desktop_sound => \1,
        mention_keys  => \1,
        channel       => \1,
        first_name    => \1,
    },
});
update_roles()

Update a user's roles

Valid roles are system_user and system_admin.

my $response = $resource->update_roles('USER-ID-HERE', [
    'ROLE-NAME-HERE',
    'ANOTHER-ROLE-HERE',
]);
generate_mfa_secret()

Generate MFA secret

Returns a base64 encoded QR code image.

my $response = $resource->generate_mfa_secret('USER-ID-HERE');
update_mfa()

Update a user's MFA

Set whether a user requires multi-factor auth. If the user currently has MFA active, a code from the MFA client is required.

my $response = $resource->update_mfa('ID-HERE', {
    activate => \1,   # or \0 for false
    code     => 1234, # required if MFA is already active
});
get_profile_image()

Get user's profile image

Get a user's profile image. Warning: returns binary content.

my $response = $resource->get_profile_image('ID-HERE');

# $response->raw_content contains the image as binary
set_profile_image()

Set user's profile image

Set a user's profile image.

my $response = $resource->set_profile_image('ID-HERE', '/path/to/file.jpg');
update_active_status()

Update user active status

Set a user as active or inactive.

$resource->update_active_status('ID-HERE', {
    active => \1, # \1 for true, \0 for false
});
update_password()

Update a user's password

my $response = $resource->update_password('ID-HERE', {
    old_password => '...',
    new_password => '...',
});
update_authentication_method()

Update a user's authentication method

my $response = $resource->update_authentication_method('USER-ID-HERE', {
    # Optional parameters:
    auth_data    => '...',
    auth_service => '...',
    password     => '...',
});
get_status()

Get a user's status

my $response = $resource->get_status('USER-ID-HERE');
set_status()

Update a user's status

my $response = $resource->set_status('USER-ID-HERE', 'STATUS-HERE');

Available statuses are "online", "away", "offline" and "dnd".

get_sessions()

Get a user's sessions

my $response = $resource->get_sessions('USER-ID-HERE');
revoke_session()

Revoke a user sesssion

my $response = $resource->revoke_session('USER-ID-HERE', 'SESSION-ID-HERE');
revoke_all_sessions()

Revoke all active sessions for a user

my $response = $resource->revoke_all_sessions('USER-ID-HERE');
get_preferences()

Get the user's preferences

my $response = $resource->get_preferences('USER-ID-HERE');
set_preferences()

Save the user's preferences

my $response = $resource->set_preferences('USER-ID-HERE', [
    { user_id => 'USER-ID-HERE', category => '...', name => '...', value => '...' },
    { user_id => 'USER-ID-HERE', category => '...', name => '...', value => '...' },
    { user_id => 'USER-ID-HERE', category => '...', name => '...', value => '...' },
]);
delete_preferences()

Delete user's preferences

my $response = $resource->delete_preferences('USER-ID-HERE', [
    { user_id => 'USER-ID-HERE', category => '...', name => '...', value => '...' },
    { user_id => 'USER-ID-HERE', category => '...', name => '...', value => '...' },
    { user_id => 'USER-ID-HERE', category => '...', name => '...', value => '...' },
]);
list_preferences_by_category()

List a user's preferences by category

my $response = $resource->list_preferences_by_category('USER-ID-HERE', 'CATEGORY-HERE');
get_preference_by_category_and_name()

Get a specific user preference

my $response = $resource->get_preference_by_category_and_name(
    'USER-ID-HERE',
    'CATEGORY-HERE',
    'NAME-HERE',
);
get_flagged_posts()

Get a list of flagged posts

Retrieve a list of posts flagged by the user with the given ID.

my $response = $resource->get_flagged_posts('USER-ID-HERE', {
    # Optional parameters
    team_id    => '...',
    channel_id => '...',
    page       => 0,
    per_page   => 60,
});
remove_reaction()

Remove a reaction from a user's post

my $response = $resource->remove_reaction(
    'USER-ID-HERE',
    'POST-ID-HERE',
    'EMOJI-NAME-HERE',
);
get_authorized_apps()

Alias for get_authorised_apps().

get_authorised_apps()

Get authorized OAuth apps

my $response = $resource->get_authorised_apps('USER-ID-HERE', {
    # Optional parameters:
    page     => 0,
    per_page => 60,
});

AUTHOR

Mike Jones <mike@netsplit.org.uk>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2020 by Mike Jones.

This is free software, licensed under:

The MIT (X11) License