Messaging service api always returns <RESPONSE 401>

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


same result, i used my ip this time

I did try 0.0.0.0 and it gave me a 401 unauthorized response so I had to use my actual ip to get it to work.

Perhaps try regenerating the key and using the new key? Have you googled what your ip is? How did you figure out what it was otherwise?

1 Like

I used my old program to figure out my IP.
I will try this, if it dosent work ill try googling my IP and regening key

THANK YOU SO MUCH. This worked.

1 Like

What was it specifically that worked? The ip or regenerating the key?

1 Like

I put my IP then regenning the key. Then worked

1 Like

Its 0.0.0.0/0 by the way

2 Likes

tried that too didnt work. i guess the ip system is broken but it works now

It uses CIDR notation so you’ll need the /0 if you want to allow for all IP addresses. It’s possible that for certain networks that your IP address might be different. One of the easiest ways to get your IP is to just search “what’s my ip” in Google search and it’ll tell you where you’re making a request from.

1 Like