Messaging service api always returns <RESPONSE 401>

Making sure everything on this page Communicating to Live Servers from External Tools | Roblox Creator Documentation has been done

1 Like


I think this is the cause. i tested through studio, i will try ingame

1 Like

nope, everything was right

1 Like

When writing rblx (although in NodeJS), I had the same issue initially. Make sure you’ve done these things:

  • Try in a live experience (serverscript that listens on a topic and prints the provided params)
-- Prety sure this is how to subscribe to a topic, haven't really worked a ton with MessagingService yet
game:GetService("MessagingService"):SubscribeAsync("topicName", function(...)
    print(...) -- print params
end)
  • Make sure the API key is not expired, is active, and has the MessagingService service added to it
  • Use the following Python code & fill in the blanks:
import requests

api_key = # your API key
universe_id = 3702278406
url_format = "https://apis.roblox.com/messaging-service/v1/universes/{universeId}/topics/{topic}"

def main():
    url = url_format.format(universeId = universe_id, topic = "test")
    response = requests.post(
        url,
        headers = {
            "x-api-key": api_key
        },
        json = {
            "message": # data here
        })
    print(response)

if __name__ == "__main__":
    main()
1 Like

how many times will i say its not expired and i set it correctly though

I did. The message didnt appear and when i did a test code message publish in lua it works.

I already tried this code. Why did you just copy paste a guys solution but slightly edit it?

1 Like

its 100% system broken as i also tried it via postman and it returned the same error.

1 Like

It doesn’t hurt to check again, you may have missed something (maybe the experience operations?)

Could I see the code you used? Does the topic name match up with the Python script?

For one, that snippet is the simplest & most efficient way to accomplish that task, therefore I did modify the snippet to my liking instead of just having to retype the exact same thing, which is completely fine.

I’m not sure what to tell you. It is working perfectly fine on my end.

image

// Using rblx
it('should send MessagingService', async () => {
	let res = await uni.publishToTopic('newtopic1', { hello: "world" });
	console.log(res);
});
-- Server
game:GetService("MessagingService"):SubscribeAsync("newtopic1", function(...)
	game.ReplicatedStorage.SubscribeTopic:FireAllClients(...)
end)
-- Client
local HTTP = game:GetService("HttpService")

game.ReplicatedStorage.SubscribeTopic.OnClientEvent:Connect(function(...)
	warn(...)
	warn(HTTP:JSONEncode(...))
	warn(HTTP:JSONDecode(...))
	warn("-----------------")
end)
1 Like

i rechecked it alot of times

if the topic name DIDNT match up with the python script, it would not return this error at all. and yess its correct.

I already tried it and there is no need to reuse it.

maybe it affects a few users only? possibly a bug.

Are you telling me I have to make some node js proxy and that its a “code issue”? Sure ill try. but im not a fan of roblox modules so ill probably not use that

Well technically i already have that except it logs it in the chat.

1 Like

if it worked for you, then its very likely a few affected users issue. because i also tried it via postman.

1 Like

If this helps, this is how I handle publishToTopic:

async publishToTopic(topic: string, data: any) {
	let url = Util.URIs.MessagingService;
	let res = await Util.octokit(url, {
		universeId: this.id,
		topic: topic
	}, {
		method: 'POST',
		headers: {
			'x-api-key': this.#apikey,
			'Content-Type': 'application/json'
		},
		body: JSON.stringify({
			message: JSON.stringify(data)
		})
	});
	if (res.status === 200) {
		return res.data;
	} else {
		console.error(res.status, res.statusText);
	}
}
1 Like

i will try this snippet later, will mark as solution if it works

1 Like

Don’t use the snippet by itself as it depends on a lot of other internal rblx stuff that I didn’t include, such as Util. Just npm install rblx & use the following snippet instead:

// CommonJS
const { OpenCloudUniverse } = require('rblx');
const API_KEY = // API key here
const UNIVERSE_ID = // Universe ID here

let uni = new OpenCloudUniverse(UNIVERSE_ID);
uni.authenticate(API_KEY);

await uni.publishToTopic('newtopic1', { hello: "world" });
1 Like

Have you tried trying it while ingame? As the messaging service API only works ingame.

The fact that postman also didn’t work is consistent with your api key not being set correctly. What does your creator dashboard view of the api key look like when you click edit on it? Make sure to either cover the actual key / regenerate it though.

Also what do you mean by this? It sounds like you may have entered the wrong IP. Your best bet is to use a local tool (use local python code rather than a website like postman) and to find out your actual public ip by googling “what is my ip”

alright.

Yeah.

I did this a billion times dude

I already have the postman app so it should sent the request via my IP. I used to put my IP only as allowed then I made it for everyone to prevent errors.

I just asked you to show what it looks like.

The bottom line is that if you’re not going to try the things people have been asking then people can’t help you.

Alright. when I get on pc ill show ot

That ip address won’t work for sure. Make sure you use your public ip address (i.e. not one that’s like 192.168.0.1 as that is typically a local one) use google to find it.

I did some testing and the only way I found to get the 403 response was to not have the correct place / experience details set up. You can copy the correct universe id from that page.

In the api docs, it states that if you add the ip address 0.0.0.0, It will allow anyone to use the api.

But ill try