Validation error: "missing serviceId in 'service-id' header"

Hi,

This is somewhat related to this post I created LobbyService (401) HTTP/1.1 401 Unauthorized on Multiplay Dedicated Server.

I tried creating the Lobby with the REST API instead and I get the following error

Lobby creation failed: {
  code: 16000,
  detail: 'request failed validation',
  details: [
    {
      errorType: 'validation',
      message: "missing serviceId in 'service-id' header"
    }
  ],
  status: 400,
  title: 'Bad Request',
  type: 'http://unity3d/lobby/errors/validation-error'
}

That the function I use to create the Lobby

router.post('/createlobby', async function (req, res) {
    try {
        const unformattedOptions = req.body;
        const options = {
            "name": req.query.name,
            "maxPlayers": 4,
            "isPrivate": null,
            "isLocked": null,
            "player": {
                "id": unformattedOptions["Player"].id
            },
            "password": null,
            "data": {}
        };      

        const accessToken = await GetStatelessToken();

        const url = "https://lobby.services.api.unity.com/v1/create";
        const response = await fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${accessToken.accessToken}`,
            },
            body: JSON.stringify(options)
        });

        if (!response.ok) {
            const errorDetails = await response.json();
            console.error("Lobby creation failed:", errorDetails);
            res.status(400).send(errorDetails);
            return;
        }

        const lobbyResult = await response.json();
        console.log("Lobby created successfully:", lobbyResult);
        res.send(lobbyResult);     
    }
    catch (error) {
        console.error('Request Failed:', error);
    }
});

I’m quite certain my GetStatelessToken function works well. I have no issue using it with Cloudsave or Matchmaker. I tried creating the Lobby on the client side, there was no issue.

I could not find any information about the above error, any help would be much appreciated. It’s not clear if the issue is from the HTTP request header or from the authorization token.

EDIT: the data I’m passing the the boddy of the request

{"name":"Test","maxPlayers":4,"isPrivate":null,"isLocked":null,"player":{"id":"USERID"},"password":null,"data":{}}

I checked the USERID in the print to compare it to the Cloudsave entry and it matches.

Solutions find while exploring commands on the CLI. “service-id” actually refers to “HostId” and the problem with the Lobby creation using a service account is that no host id is provided. By providing the hostid as parameter in the CLI with --service-id HOST_ID

D:\Development\Unity\CLI>ugs lobby create lobby.json --service-id **DefaultHostId**
class Lobby {
  Id: wjckW79oe6QVHfFLYapAgH
  LobbyCode: 77JRDF
  Upid: ...
  EnvironmentId: ...
  Name: Test
  MaxPlayers: 4
  AvailableSlots: 4
  IsPrivate: False
  IsLocked: False
  HasPassword: False
  Players: System.Collections.Generic.List`1[Unity.Services.MpsLobby.LobbyApiV1.Generated.Model.Player]
  Data:
  HostId: **DefaultHostId**
  Created: 04.02.2025 00:51:32
  LastUpdated: 04.02.2025 00:51:32
  _Version: 1
}

or by adding a header to the REST API call

const response = await fetch(url, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${accessToken.accessToken}`,
        'service-id': hostId,
    },
    body: JSON.stringify(options)
});

It would be great to update the docs as follows:

  • Update the SDK docs to mention it’s not possible to run the create function (maybe others Lobby functions?) on a dedicated server.
  • Update the REST API Doc to specify that the service-id must be provided as a header to indicate who is the HostId
  • Perhaps update the error message and make it clearer that the HostID is missing in the header instead of service-id.