RPC Code: 3 Error when adding friends (Godot)

I am experiencing some issues getting add_friends_async to work.
I’m following along with the documentation for friends: Nakama: Friends | Heroic Labs Documentation
But I get the following response when i call the function with a username:

=== Nakama : DEBUG === Request 4 returned response code: 400, RPC code: 3, error: No valid ID or username was provided.

I know that the username is valid. I can see it in Nakama console in the username field. I also checked output of the form used to fill in the username to check if nothing is causing issues there and it all seems like add_friends_async( ) is getting the right information.


func add_friend(username: String) -> NakamaAsyncResult:
	var result : NakamaAsyncResult = yield(_client.add_friends_async(_session, null, username), "completed")
	if not result.is_exception():
		return result
	else:
		return result.get_exception().status_code

I am trying to add user by username so i have set ID to Null. According to documentation this should be fine. But i can’t quite seem to find whats going wrong.

I’m running Godot 3.5, Nakama Version 3.12.0 and CockroachDB Version 20.2.19

For anyone encountering this issue in the future.

I was a little stupid and thought the code example in Nakama: Friends | Heroic Labs Documentation used array’s because it was adding two id’s. But the array contains a string. I figured i could just pass the string directly into add_friend_async().

This does not work and was causing the RPC code 3. You have to put the data you are passing into an array. Below is an example of my updated code. Hopefully this will help someone.

func add_friend(username: String) -> NakamaAsyncResult:
	var user = [username]
	var result : NakamaAsyncResult = yield(_client.add_friends_async(_session, null, user), "completed")
	if not result.is_exception():
		return result
	else:
		return result.get_exception().status_code