Yes, there was a live server with the code necessary to receive the request running on it as well. I’m fairly certain the whole process of sending the POST request is correct as why would it send a response message of “OK” if it wasn’t. Though I’m still lost on why nothing is received ingame with the help of SubscribeAsync function
Are we ever going to get official support for creating developer products, currently we have to use the client API to do this which does not work very well especially when it involves the usage of cookies.
Repost from Recent and Upcoming Changes to Roblox Web APIs - #36 by parker02311
I have been waiting for this for soo long. This removes the need of long polling our web servers to send data to roblox games servers. I see many opportunities open up with this. Thanks for considering our feedback!
We’re tackling APIs piece-by-piece. I don’t have an official timeline to share but this is something we plan on exploring further.
This is something we’re working on as well. Our updated docs site will eventually support this functionality.
Now if only I knew how to use this…
For some reason it doesn’t work, I did everything as written in the documentation, I even receive the proper response and Roblox script doesn’t receive anything.
server.lua
local MessagingService = game:GetService("MessagingService")
MessagingService:SubscribeAsync("test", function(message)
print("Fired", message)
end)
server.js
import fetch from "node-fetch";
var topic = "test";
var message = "hi";
var url = `https://apis.roblox.com/messaging-service/v1/universes/${universeId}/topics/${topic}`;
var headers = {
"x-api-key": key,
"Content-Type": "application/json"
};
var body = JSON.stringify({
message: message
});
var response = await fetch(url, {
method: "POST",
headers: headers,
body: body
});
I get 200
which means OK
, along with empty response body.
We’re investigating this issue. Will report back once we figure out what’s going on.
----- EDIT -----
We found the problem and we’re working on a fix. We’ll let you know when it’s released.
I like that you give examples, but, the example you give is very limiting. I’m wondering how you would send a JSON object to the request.
So let’s say I have this:
{
"Color": {"R": 255, "G": 255, "B": 0},
"Message": "This is the Cloud API!",
"Header": "Cloud API Announcement"
}
Would I need to shove this JSON into the message string as a string? Or would I be able to give the JSON object directly (like below) and it’d work?
{
"message": {
"Color": {"R": 255, "G": 255, "B": 0},
"Message": "This is the Cloud API!",
"Header": "Cloud API Announcement"
}
}
You can definitely send a JSON encoded string, example:
{
"message":"{\"Content\": { \"Subcontent\": 123}"
}
We have identified and issued a fix, please try the request again.
Yup, it works now.
Amazing, great job roblox! This will be very useful for connecting external apps and servers to roblox. We can finally make better web-based admin panels and connect other platforms without sending thousands of HTTP requests (or using long polling), they take a lot of server resources.
The Open Cloud continues to surprise me with it’s new features. Keep it up Roblox!
I tried to use the API but I keep getting error 500 server internal error is there something wrong in my code?
import requests
import json
import Credentials as c
Key = c.Private_Key
UniverseId = c.Univ_Id
TopicId = c.TopicId
Data = "test"
Data = json.dumps(Data)
JsonData = json.loads(Data)
url = 'https://apis.roblox.com/messaging-service/v1/universes/'+ UniverseId +'/topics/'+ TopicId
headers = {'x-api-key': Key,'content-type': 'application/json'}
body = JsonData
response = requests.post(url, data = body, headers = headers)
print(url)
print(body)
print(response)
Yeah, try visiting apis.roblox.com or api.roblox.com either one of them does not exist (yet) or one has internal server error
For anyone having a hard time figuring out how to make discord.js to ROBLOX for this I’m going to share my Documentation here,
const topic = "Any-Name-Here"
const universeId = "0000000" -- (get this when editing experience, the link is universeid)
const url = `https://apis.roblox.com/messaging-service/v1/universes/${universeId}/topics/${topic}`
const key = `put-your-api-key-here`
const headers = {
"x-api-key": key,
"Content-Type": "application/json"
};
let msg = interaction.options.getString('message') -- i am using slash commands here, to get the string from the message.
let body = JSON.stringify({
message: msg
});
var response = await fetch(url, {
method: "POST",
headers: headers,
body: body
});
-- its also always good to add error handling :)
try{
await interaction.reply({ embeds: [make-an-embed]});
console.log(response)
} catch (error){
console.log(error)
await interaction.reply({ embeds: [make-another-embed]});
}
}
The node.js part being done, i also have a ROBLOX handler, which is a server script!
I recommend using RemoteEvents when you’re trying to make it appear in chat.
local Example = game:GetService("ReplicatedStorage").Events.lolevent:FireAllClients
local MessagingService = game:GetService("MessagingService")
MessagingService:SubscribeAsync("Any-Name-Here", function(message)
-- put code here
Example(message.Data) -- make sure not to forget the "D" has to be upper case, or you'll get an error
end)
I hope this could kinda help out some people because even this was very confusing for me, and even had to get some help, so I decided to put this out so the struggle isn’t that hard.
I wish you a nice and productive day!
Are there any plans to supporting subscribing externally?
That error got resolved by editing the code, try using a different POSTing method maybe, or your API-Key doesn’t have the permissions (try first pls), if it still don’t work then I don’t know
Do you mind sharing how you edited the code to solve the error? I use the same method you are using and it doesn’t work