How to get all users who are not friends

I would like to know if there is a way for a user to get a list of all other users who are currently not in a friend state with the calling user, where we can pass in the limit and cursor.

I am currently using nk.sqlQuery to fetch all the users, and then filtering out those who are friends, but I want to know if there is a better/more efficient way to implement this functionality.

Hello @accountexeregister,

The friend list API takes in an optional state, if not present friends in all states will be returned, you should filter the ones in the friend state (0) from the results to get only the ones in any other state.

Hope this helps.

Hi @sesposito, I am trying to get the users who are not in any friend state (neither 0, 1, 2, 3). Is there any built in API for this? Ideally, there should be pagination and username search filtering.

Apologies I had misunderstood the question - what is the need for this?

One way is to create “recommended” friends list this is usually what do game do with friends system. Works well.

If the intent is to recommend friends, one could list the user friends first, then use the usersGetRandom function filtering out any users that are in the friend list.

Another option is to use the recently introduced friendsOfFriendsList.

Hope this helps.