Problem with messaging service api

I am currently trying to accces the roblox messaging service api using javascript and I got this module from @LifeDigger maybe you or somebody else can help me. If I post the request I just won’t get the output in roblox. It says message sent sucessfully every time but i just can’t get an output in roblox.

Calling th function:

const message = require('../../../src/sendmessage');
message.MessageSend(memberroles, "roles", interaction);

Javascript module:

const axios = require('axios').default

    const response = await axios.post(
        `https://apis.roblox.com/messaging-service/v1/universes/${process.env.UNIVERSE_ID}/topics/${Topic}`,
        {
            'message': JSON.stringify({Message})
        },
        {
            headers: {
                'x-api-key': process.env.OPENCLOUD_KEY,
                'Content-Type': 'application/json'
            }
        }
    ).catch(err =>{
        console.log(err.response.status)
        if (err.response.status == 401) return console.log(`**Error:** API key not valid for operation, user does not have authorization`)
        if (err.response.status == 403) return console.log(`**Error:** Publish is not allowed on universe.`)
        if (err.response.status == 500) return console.log(`**Error:** Server internal error / Unknown error.`)
        if (err.response.status == 400){
            if (err.response.data == "requestMessage cannot be longer than 1024 characters. (Parameter 'requestMessage')") return console.log(`**Error:** The request message cannot be longer then 1024 characters long.`)
            console.log(err.response.data)
        }
  })
  console.log(response);
    if (response){
        if (response.status == 200) return console.log(`Message sucessfully sent!`, response)
        if (response.status != 200) return console.log(`**Error:** An unknown issue has occurred.`)
    }

Roblox code:

local MessagingService = game:GetService("MessagingService")
local HttpService = game:GetService("HttpService")

MessagingService:SubscribeAsync("roles", function(requestInfo)
	print(1)
	local data = requestInfo.Data
	local DecodedData = HttpService:JSONDecode(data)
		
	print(data, DecodedData)
end)

Lastly a screenshot from the api key settings:

If you need aditional info just reply to this post.
Thx in advance.

1 Like

Does it print anything at all? You test it in game or studio/team test? Response returns status 200?

So it doesn’t print anything in studio not even the 1 and I am doing a single player test not a team test. The response.status returns 200 and it logs "sent sucessfully " in vs code console

This is normal behavior as the MessagingService ONLY works in the game.

1 Like

Hell nah i didn’t know about that. Thx for helping out i was trying to find the error for 2 hours and you saved me lol.

1 Like

Yea its only works in game servers like what @3YbuKtOp has already said. The reason why is because the messaging service sends a live message to all servers but when your play testing in studio your technicality not playing on a Roblox server so it does not send it to your studio.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.