"Bad Request" error message when connecting as client using Unity relay services

So I’m using netcode for gameobjects along with relay service to make a multiplayer game (this is my first time btw). But when connecting with the client I somehow get an error saying Bad Request

Here’s the code:

    public struct RelayJoinData
    {
            public string JoinCode;
            public string IPv4Address;
            public ushort Port;
            public Guid AllocationID;
            public byte[] AllocationIDBytes;
            public byte[] ConnectionData;
            public byte[] Key;
            public byte[] HostConnectionData;
    }

    public async Task<RelayJoinData> JoinGame(string joinCode)
    {
    //Initialize the Unity Services engine
    await UnityServices.InitializeAsync();
    //Always autheticate your users beforehand
    if (!AuthenticationService.Instance.IsSignedIn)
    {
        //If not already logged, log the user in
        await AuthenticationService.Instance.SignInAnonymouslyAsync();
    }

    
    JoinAllocation joinAllocation = await Relay.Instance.JoinAllocationAsync(joinCode);
    RelayJoinData data = new RelayJoinData
    {
        Key = joinAllocation.Key,
        Port = (ushort)joinAllocation.RelayServer.Port,
        AllocationID = joinAllocation.AllocationId,
        AllocationIDBytes = joinAllocation.AllocationIdBytes,
        ConnectionData = joinAllocation.ConnectionData,
        HostConnectionData = joinAllocation.HostConnectionData,
        IPv4Address = joinAllocation.RelayServer.IpV4,
        JoinCode = joinCode
    };

    Transport.SetRelayServerData(data.IPv4Address, data.Port, data.AllocationIDBytes, data.Key, data.ConnectionData, data.HostConnectionData);
    return data;
}

I tracked the error down and it seems this line is the cause of the error

JoinAllocation joinAllocation = await Relay.Instance.JoinAllocationAsync(joinCode);

However, if I change the input for JoinAllocationAsync to a fixed string (e.g: “WJBPKB”), it returns error 404 Not Found

Error: HttpException1: HTTP/1.1 400 Bad Request Unity.Services.Relay.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.Relay.Http.HttpClientResponse response, System.Collections.Generic.Dictionary2[TKey,TValue] statusCodeToTypeMap) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/Http/ResponseHandler.cs:103)
Unity.Services.Relay.Http.ResponseHandler.HandleAsyncResponse[T] (Unity.Services.Relay.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/Http/ResponseHandler.cs:186)
Unity.Services.Relay.Apis.Allocations.AllocationsApiClient.JoinRelayAsync (Unity.Services.Relay.Allocations.JoinRelayRequest request, Unity.Services.Relay.Configuration operationConfiguration) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/Apis/AllocationsApi.cs:188)
Unity.Services.Relay.WrappedRelayService.JoinAllocationAsync (System.String joinCode) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/SDK/WrappedRelayService.cs:144)
Rethrow as RelayServiceException: Bad Request: invalid request schema or decoding failure
Unity.Services.Relay.WrappedRelayService.JoinAllocationAsync (System.String joinCode) (at Library/PackageCache/com.unity.services.relay@1.0.1-pre.5/Runtime/SDK/WrappedRelayService.cs:150)
RelayManager.JoinGame (System.String joinCode) (at Assets/Scripts/RelayManager.cs:108)
UIManager.b__9_1 () (at Assets/Scripts/UIManager.cs:41)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) (at <7b935204f5ff4bcab44b3b0ebca330bf>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at :0)
UnityEngine.UnitySynchronizationContext.Exec () (at :0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at :0)

Anyone know how to fix this error. This is the first time I’ve gotten this and I’m kind of confused

I was having this problem, for me the issue came from reading the join code from an TMPro input field. Which added an empty character on the end of the string. To fix I just edit the string so I only care about the first 6 characters before I send it off. Just put this code in before you use the joinCode.

        joinCode = joinCode.Substring(0, 6);

same here… It is the first time I am testing this so I cannot be sure the error is not somewhere in my part of the code though…
Was it working for you before?

Same here…
updating the Relay to pre5 did not help. Did you have it working before?
I will give it a go on two separate devices tomorrow, I was using parallelsync from one computer, maybe that is the issue.

Hello guys, dit you find the solution ?

I tried to implement the relay service too and got the same error when try to connect on clients.
The host looks working fine as it shown an PlayerObject.

I tried to pass custom code or used Relay.Instance.GetJoinCodeAsync(Data.AllocationID), neither works!

Did you also join host with JoinAllocationAsync(joinCode)? Because if you do, host will be connected as client and relay will be timed out. So then you get your error 404 Not Found.

Did you also join host with JoinAllocationAsync(joinCode)? Because if you do, host will be connected as client and relay without host will be timed out. So then you get your error 404 Not Found.

@Tuantin

Give this a try:
Once you get the join code on from starting the host.

Go to your code and HARDCODE that string into the JoinAllocationAsync,
Rebuild and deploy to the other headset.

That worked for me.

It has to be related to how the string is encoded/decoded, or how TextMeshProUGUI treats strings.

I am new to C# so if anyone knows…

Any solution for this? Happens just randomly. It worked previously