# Invalid Match Id (Empty string)

**URL:** <https://forum.heroiclabs.com/t/invalid-match-id-empty-string/56>\
**Category:** Local Setup\
**Created:** [July 9, 2019, 3:26am UTC](https://forum.heroiclabs.com/t/invalid-match-id-empty-string/56 "2019-07-09T03:26:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![spentak](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@spentak](https://forum.heroiclabs.com/u/spentak)\
**Post date:** [July 9, 2019, 3:26am UTC](https://forum.heroiclabs.com/t/invalid-match-id-empty-string/56/1 "2019-07-09T03:26:28Z")

</div>

I’m using Nakama C++ with Unreal Engine.

I’ve got it working up to Authentication, joining pools, and authentication. However when I try to join the match I get an “Invalid match id” error.

If I debug I notice that the matchId is an empty string. The debug printout:

```
matchId = ""
    ticket = "6debf08e-af61-4826-8271-c902eda8579e"
    token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NjI2NDI1MjIsIm1pZCI6IjRmMTg3ODM0LTBkNmMtNDU0OC05OTE1LTcyZmI1MzAyOTU0Ni4ifQ.HDEZbHaHcMmimRaoO2rN2bkhG25fimNQEJuT4sGSD6g"

```

Here is the code:

```
void UNetworkManager::FindMatch() {
	int32_t minPlayers = 2;
	int32_t maxPlayers = 2;
	std::string query = "*";

	auto onJoinedPool = [](const NMatchmakerTicket& ticket) {
		UE_LOG(LogTemp, Warning, TEXT("Nakama: Joined Pool"));
	};

	RTNetworkClient->addMatchmaker(minPlayers, maxPlayers, query, {}, {}, onJoinedPool);

	NetworkListener.setMatchmakerMatchedCallback([this](NMatchmakerMatchedPtr matched)
	{
		UE_LOG(LogTemp, Warning, TEXT("Nakama: Match Found"));
		JoinMatch(matched->token);
	});
}

void UNetworkManager::JoinMatch(string matchId)
{
	RTNetworkClient->joinMatch(matchId, [this](const NMatch& match)
	{	
			UE_LOG(LogTemp, Warning, TEXT("Nakama: Joining Match"));
			std::vector<FNetworkUser> users(match.presences.size());
			std::transform(match.presences.begin(), match.presences.end(), users.begin(), [](NUserPresence user) {
				return FNetworkUser { user.username.c_str(), user.userId.c_str() };
			});

			if (users.size() > 0)
			{
				TArray<FNetworkUser> usersTArr;
				usersTArr.Append(&users[0], users.size());

				FNetworkUser currentUser{ match.self.username.c_str(), match.self.userId.c_str() };
				OnMatchFound(FMatchInfo{ match.matchId.c_str(), currentUser, usersTArr });
			}
			
	});
}

```

If it helps, what I’m trying to do is match any two players in a 1v1 realtime game. I _thought_ matchmaking could do this for me without having to have a client call `createMatch`

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [July 9, 2019, 11:12am UTC](https://forum.heroiclabs.com/t/invalid-match-id-empty-string/56/2 "2019-07-09T11:12:48Z")

</div>

Hi @spentak. You’re on track and all the code you’ve shown looks good.

The difference with the matchmaker and relayed matches created by client-side code is that the matchmaker will give you a token that you use to join the match with. This token is used by the game server to create the match if no other peers are connected to it at the time of the initial join by the current player.

This design choice is because the matchmaker does not create a match on the server (i.e. a multiplayer stream if it’s a relayed match) but instead gives the player a way to join which can be validated by the server. (The token is actually a JWT with a signing key.)

You can see more docs on it [here](https://heroiclabs.com/docs/gameplay-matchmaker/#join-a-match).

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Dimon4eg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/dimon4eg/32/33_2.png) [@Dimon4eg](https://forum.heroiclabs.com/u/Dimon4eg)\
**Post date:** [July 9, 2019, 11:18am UTC](https://forum.heroiclabs.com/t/invalid-match-id-empty-string/56/3 "2019-07-09T11:18:26Z")

</div>

From code you posted I don’t see how `JoinMatch` is implemented.  
You should use [joinMatchByToken](https://heroiclabs.github.io/nakama-cpp/html/class_nakama_1_1_n_rt_client_interface.html#a8491324322b2a847351bd157b45e7c0a) method.

---

<div class="post-metadata">

**Author:** ![spentak](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@spentak](https://forum.heroiclabs.com/u/spentak)\
**Post date:** [July 9, 2019, 1:44pm UTC](https://forum.heroiclabs.com/t/invalid-match-id-empty-string/56/4 "2019-07-09T13:44:01Z")

</div>

Okay `joinMatchByToken` is what I needed. Thanks for the help!

Honestly, I went through every page of gameplay docs and didn’t see this anywhere. One of the really hard things coming into Nakama brand new is understanding the flow.

I think it would be super helpful to have some small example projects. The code snippets have no context. Or maybe even just some flow diagrams.

ie  
SampleProject: Creating and joining a realtime multiplayer game  
SampleProject: Creating and joining a turn based multiplayer game

---

<div class="post-metadata">

**Author:** ![Dimon4eg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/dimon4eg/32/33_2.png) [@Dimon4eg](https://forum.heroiclabs.com/u/Dimon4eg)\
**Post date:** [July 9, 2019, 2:03pm UTC](https://forum.heroiclabs.com/t/invalid-match-id-empty-string/56/5 "2019-07-09T14:03:52Z")

</div>

Glad you solved the issue.  
Yes, will update docs 👍

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [July 9, 2019, 5:27pm UTC](https://forum.heroiclabs.com/t/invalid-match-id-empty-string/56/6 "2019-07-09T17:27:58Z")

</div>

> SampleProject: Creating and joining a realtime multiplayer game  
> SampleProject: Creating and joining a turn based multiplayer game

This is a great suggestion. We do have a full example project for Unity Engine which shows a realtime multiplayer game:

> **[GitHub - heroiclabs/unity-sampleproject: A sample game called Pirate Panic...](https://github.com/heroiclabs/unity-sampleproject)**
>
> A sample game called Pirate Panic for Unity engine built with Nakama server. - GitHub - heroiclabs/unity-sampleproject: A sample game called Pirate Panic for Unity engine built with Nakama server.

This won’t be directly useful because it’s not a C++ project but does show a contextual example on how to use pretty much all of the APIs in the game server.
