So I’ve been stuck on this for the past 4 hours, and I can’t seem to wrap my head around it. I’ve gone as far as to completely copying and pasting javascript code from a devforum post, and it still does not work.
Code in Studio (this ones probaly unimportant, see nodejs code below)
local MessagingManager = {}
local MessagingService = game:GetService("MessagingService")
local HttpService = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")
function MessagingManager:Init()
MessagingService:SubscribeAsync("GlobalModeration", function(message)
print(message.Data)
end)
end
return MessagingManager
NodeJS Code (the important one, which shows the error)
const axios = require('axios').default
module.exports.MessageSend = async function MessageSend(Message, Topic) {
const response = await axios.post(
`https://apis.roblox.com/messaging-service/v1/universes/4204279113/topics/${Topic}`,
{
'message': Message
},
{
headers: {
'x-api-key': 'the api key',
'Content-Type': 'application/json'
}
}
).catch(err =>{
console.log(err.response.status)
if (err.response.status == 401) return console.log(`api key invalid, not authorized`)
if (err.response.status == 403) return console.log(`denied, publish possibly not allowed on universe, not authorized`)
if (err.response.status == 500) return console.log(`internal server error, not authorized`)
if (err.response.status == 400){
if (err.response.data == "requestMessage cannot be longer than 1024 characters. (Parameter 'requestMessage')") return console.log(`request message cannot be longer than 1024 characters, not authorized`)
console.log(err.response.data)
}
})
if (response){
if (response.status == 200) return console.log(`200 OK`)
if (response.status != 200) return console.log(`unknown error occured, not authorized`)
}
}
If you perceived the NodeJS code above as similar, that is because I’ve copied it from the devforum post as an act of desperation.
Also, yes, HttpService and API Services are both enabled in the game.
Any help appreciated thanks.