Get User Sessions

Overview

This guide covers how to get a user's active sessions, which can be used as a way to show their online status.

Get a User's Sessions

Given a user's ID you can get their sessions. The call to get a user's sessions is paginated.

application.getUserSessions({ user_id: "USR-id", page_size: 20 }).then((user_sessions_page) => {
  // handle page of sessions
}).catch((error) => {
  // handle error
});
client.getUserSessions("USR-id", 20, NexmoPageOrder.NexmoMPageOrderAsc, object: NexmoRequestListener<NexmoUserSessionsPage> {
    override fun onSuccess(result: NexmoUserSessionsPage?) {
        // handle page of sessions
    }

    override fun onError(error: NexmoApiError) {
        // handle error
    }
})

You can also call this function with a NexmoUser object:

user.getSessions(20, NexmoPageOrder.NexmoMPageOrderAsc, object: NexmoRequestListener<NexmoUserSessionsPage> {
    override fun onSuccess(result: NexmoUserSessionsPage?) {
        // handle page of sessions
    }

    override fun onError(error: NexmoApiError) {
        // handle error
    }
})
client.getUserSessions("USR-id", 20, NexmoPageOrder.NexmoMPageOrderAsc, new NexmoRequestListener<NexmoUserSessionsPage>() {
    @Override
    public void onSuccess(@Nullable NexmoUserSessionsPage result) {
        // handle page of sessions
    }

    @Override
    public void onError(@NonNull NexmoApiError error) {
        // handle error
    }
});

You can also call this function with a NexmoUser object:

user.getSessions(20, NexmoPageOrder.NexmoMPageOrderAsc, new NexmoRequestListener<NexmoUserSessionsPage>() {
    @Override
    public void onSuccess(@Nullable NexmoUserSessionsPage result) {
        // handle page of sessions
    }

    @Override
    public void onError(@NonNull NexmoApiError error) {
        // handle error
    }
});

If the sessions page contains a session object, you can assume that the user has been recently connected to the Vonage Client SDK.