MessagingService Open Cloud Issue

I’m currently working on something on PlayFab using the OpenCloud API w/ Messaging Service.

For some reason I keep getting an error of ‘Request Body not in correct format’.

handlers.matchFound = function (args, context) {
    var psEvent = context.playStreamEvent;
    
    var result2 = http.request('https://games.roblox.com/v1/games/10555812668/servers/Public?sortOrder=Desc&excludeFullGames=false&limit=10', 'get', '{}', "application/json", null);
    var randomServer = JSON.parse(result2).data[0].id
    var TicketIds = psEvent.Payload.TicketIds
    var MatchId = psEvent.Payload.MatchId
    
    var body = {
        "message": {
            "matchID": MatchId,
            "TicketIds": TicketIds,
            "MasterServer": randomServer
        }
    };
    var content = JSON.stringify(body);
    var headers = {
        "x-api-key": "myapikey"
    }
    
    var result = http.request('https://apis.roblox.com/messaging-service/v1/universes/3835702677/topics/PLAYFAB', 'post', content, 'application/json', headers);
    return { result, content };
};

The raw content that is being sent is

"{\"message\":{\"matchID\":\"a4bc51f9-e354-4692-a06e-3bf464ff07c8\",\"TicketIds\":[\"84da4a3e-a196-4338-9eed-4494b70f8cb1\",\"93bc94e0-6ce9-41b6-9bbf-c1d0aedc84da\"],\"MasterServer\":\"11b3c3ec-5848-475c-82e0-943bbf1302db\"}}"

I’m struggling to understand why this is throwing an error, but the error is the same everytime.
image

If anyone knows why it might be throwing this issue please help! lol

1 Like

Just in-case anyone comes across a similar issue in future, it turns out when posting through, any deep arrays have to be wrapped in a stringify to send across, didn’t realise this was the case but I guess its because JavaScript and Lua are completely different.

Here’s what I did -

handlers.matchFound = function (args, context) {
    var psEvent = context.playStreamEvent;
    
    var result2 = http.request('https://games.roblox.com/v1/games/10555812668/servers/Public?sortOrder=Desc&excludeFullGames=false&limit=10', 'get', '{}', "application/json", null);
    log.info(result2)
    var randomServer = JSON.parse(result2).data[0].id
    var TicketIds = psEvent.Payload.TicketIds
    var MatchId = psEvent.Payload.MatchId
    
    var body = {
        "message": JSON.stringify({
            "masterServer": randomServer,
            "MatchID": MatchId,
            "TicketIds": JSON.stringify(TicketIds)
        })
    };
    var content = JSON.stringify(body);
    var headers = {
        "x-api-key": "API_KEY"
    }
    
    var result = http.request('https://apis.roblox.com/messaging-service/v1/universes/3835702677/topics/PLAYFAB', 'post', content, 'application/json', headers);
    return { result, content };
};
2 Likes