I’m very new to web development and I was wondering how you would make a GET/POST request to Roblox since you can’t do it using HttpService directly, so I know I’d have to use something outside of Roblox but I’m not sure what that is.
Best way is so setup a proxy and try requesting from that. There are quite a few people who’ve mentioned ways to do this, so if you search around you’ll be sure to find some ways to go about that
You would use HttpService, but you’d need a proxy, which is a bit like a literal mirror. You can turn this mirror and see someone else through it without actually looking at them.
Your request is sent to this proxy, which then personally requests the info from the Roblox domain and then relays the information back to you.
An example of a proxy you could use is rprxy.xyz
I believe what OP is asking is not how to make requests from a roblox server, it is asking how to make a request from a remote server to roblox.
May I ask what your usecase is? A lot of API that I use either return me information when I make a POST request to their server (such as pastebin) or I just continually loop GET requests (my discord server). You’re right though, there’s no way to directly receive requests.
I found this group bot api with this script inside of it that can change a Roblox user’s rank in a group using this url with an http POST request, and I am trying to do it using a Roblox script
var httpOpt = {
url: '//www.roblox.com/groups/api/change-member-rank?groupId=' + group + '&newRoleSetId=' + role.ID + '&targetUserId=' + target,
options: {
resolveWithFullResponse: true,
method: 'POST',
jar: jar,
headers: {
'X-CSRF-TOKEN': xcsrf
}
}
}
I was hoping that it just made a post request to the specified url, which meant I could do it from a Roblox script if I were able to make the post request
Ah okay, in that case Dapale and Notwal are correct that you need a proxy. To me it sounded like you wanted a listener for requests. Try Notwal’s answer, replacing roblox.com
with rprxy.xyz
.
Okay I have no idea what’s going on. I have been running this script,
local url = "https://rprxy.xyz"
local dest = "/groups/api/change-member-rank"
local groupId = 4702227
local newRole = 30
local userId = 444077685
local query = "groupId="..groupId .. "&newRoleSetId="..newRole .. "&targetUserId="..userId
local http = game:GetService("HttpService")
local request = http:PostAsync(url..dest, query, 2, true)
and each time I print out the request, it’s just a big thing of html code as a string, and when I ran it into an html code runner, it ended up just being the Roblox login website…
That’s because it isn’t logged in. You would have to send a Cookie to be logged into an account, and then you would also have the grab the XCRF token and send it with the post request. An issue with this is anyone can use that cookie to log into your account, and I’m unsure if that site that you’re using is trustworthy.
how do you grab the xcsrf token?
I’m unsure if it’s possible with that proxy service that you’re using.
I more meant how would you get it in general
I found this script, I don’t know if this means anything
Script
// Includes
var getHash = require('./getHash.js').func
var http = require('./http.js').func
var cache = require('../cache')
// Args
exports.optional = ['jar']
// Define
function getGeneralToken (jar) {
var httpOpt = {
// This will never actually sign you out because an X-CSRF-TOKEN isn't provided, only received
url: '//api.roblox.com/sign-out/v1', // REQUIRES https. Thanks for letting me know, ROBLOX...
options: {
resolveWithFullResponse: true,
method: 'POST',
jar: jar
}
}
return http(httpOpt)
.then(function (res) {
var xcsrf = res.headers['x-csrf-token']
if (xcsrf) {
return xcsrf
} else {
throw new Error('Did not receive X-CSRF-TOKEN')
}
})
}
exports.func = function (args) {
var jar = args.jar
return cache.wrap('XCSRF', getHash({jar: jar}), function () {
return getGeneralToken(jar)
})
}
Normally, you would send a GET request to any page, I use the home page when I want to get it. Inside the source you’ll find it here.
Edit:
That script could work if you got the other scripts it’s requiring at the start.
Could I use HttpService:RequestAsync() with the cookie as a header?
Yes, I believe so.
You can use postman to GET and POST
What I would do is make a node.js (javascript) app which uses express.js to set up an api endpoint a lib such as noblox.js for logging into roblox and changing someone’s rank in group, and then host it somewhere like glitch.com.
From that point you can use HttpService
to make a request to your api which will change the group rank for the target user.
An example with the noblox.js lib and express.js:
const express = require("express")
var app = express()
const rbx = require("noblox.js")
rbx.cookieLogin("your cookie here (best wa is to create a dummy account for this and rank it in group)")
app.get("/rankInGroup", function(req, res) {
var groupId = req.query.groupId;
var role = req.query.role;
var userId = req.query.userId;
rbx.setRank(groupId, userId, role).then(() => {
res.send("Success")
});
});
Then you would make a request to http://yoururl.glitch.me/rankInGroup?groupId=4702227&role=30&userId=444077685
(Forgive any typos, I typed all that on mobile)
Thank you for your answer, and especially for going into that much detail. I will attempt to do this and report back if it works .
edit: I went to glitch.com and then just did “New Project → Clone from Git Repo” and then inserted the noblox.js link into it. Would that work? When I click on “Show” this is the link that pops up https://torstcafe-app.glitch.me/
Please follow these guidelines before making a thread to ensure your question can be answered correctly, and that your thread is structured better.
From my reading of this thread, I do not quite understand what you are attempting to achieve. It would help if you were more specific and described what exactly you wanted to do.
In general - yes, you can send HTTP requests to the various Roblox API’s. Reading the documentation page for each one will provide you with detailed information on what is required to send a request successfully, this includes the HTTP Method, required or optional parameters, and whether or not you need to be logged into an authenticated user.
Take the fetch group wall posts API for example, it does not require you to be logged in, requires the method to be GET
, the only required parameter (in bold) is the groupId
, and the rest of the parameters, such as sortOrder
are optional. It also provides you with the request URL so you can try it out for yourself.
EDIT If you would like a program to send requests from for testing purposes, or for experimentation in general I highly reccomend Postman. You can use it to send HTTP requests with different methods.
So why are you making a request to roblox? Could you get by with existing services provided?
To explain, I am trying to make it so that I can create a function which allows me to change someone’s rank in a group, like API:promote(groupId, userId, rankId)
, and there is a url used by Roblox to do such a thing, which is
'//www.roblox.com/groups/api/change-member-rank?groupId=GROUPID&newRoleSetId=NEWROLESET&targetUserId=USERID'
and since HttpService doesn’t let you make requests to Roblox I have to use a proxy – but the problem is you need the login cookie and the XCRF token just to do that.