Best way to fetch users


I’m working on a nextcloud app, and one of it’s purposes is to be able to share data between users.
In order to do this I need to first fetch the list of users.
What is the best way of doing this? I’ve looked at the nextcloud code and documentation and I’ve seen some POST requests to get users, and places where the users are requested from the $store…

Could someone please point me in the right direction? What I think I’m looking for is a simple request to get a list of users and their basic information. I probably also need a way to get access to the requesttoken. However, I still can’t seem to find those functions.

Any help is appreciated. Thanks

Hi @mnassabain,

from your message I assume you are talking about the client-side? I’m not sure you really want the “list of users” as that can go into thousands easily with medium size installations. Can’t you fetch specific users instead? Also, what information about the user do you need?

Hello @ChristophWurst,
Thank you for your reply.

The goal would be to allow a user to share a certain article with other people. The basic idea is to have a input text field in which a user can search for a person. After each input change a request would be sent to the nextcloud server from our app asking for a limited list of users whos usernames match the search (for example top 5 results).

Since I’ve posted I’ve discovered the npm package @nextcloud/router, which seems to be what I’m looking for. However, I’m not entirely sure if I can use it. Our projet uses a controller to send the http request, and I’m not sure the methods from the module can be used.

So what I am trying to do is create the request in my Controller which fetches a list of users corresponding to my search query. However I cannot get the request to work… I don’t think I understand how to create the request, how to add the correct token, or something else…

The information I need for now is the username… For later I’m not sure if nextcloud already has a system allowing us to send data from a user to another… but I’d like to get the first part working before tackling a bigger problem.

Thank you

Oh and if it helps, I forgot to mention that we are trying to contribute to the nextcloud news app as part of our university project.

1 Like

I think what you are looking for is the OCS sharee API:

You can use @nextcloud/router to generate the OCS URL.

1 Like

@ChristophWurst thank you for your reply!

However I’m still having problems importing the functions for the @nextcloud/router module. I think it’s because it’s made to work with front-end. And while we are working on the front-end of the news app, it doesn’t use VueJS, it seems to have an MVC structure and uses angularjs 1.

We still haven’t managed to figure how to use the functions from the router… We’re no experts in angularjs, but is it possible that the @nextcloud/router module cannot be used with our architecture? Is there any other way to request the nextcloud server?

Thank you.

PS - I have recently contacted a maintainer of the news app and I’m awaiting his response.

You can use the deprecated OC.linkToOCS.

1 Like

Perfect! It worked! Thanks!