The Roblox API is extremely powerful - it can be used to create anything from group ranking bots to game statistics websites.
As a developer, there are two main ways you’ll want to access the Roblox API: sending the requests yourself or using one of the multiple wrappers for your favorite programming language. In this tutorial, I’ll go over both methods on how to use a wrapper for it called noblox.js
If you don’t know anything about the Roblox Api I suggest you go to this Devforum Post.
THIS WILL BE A TUTORIAL ON HOW TO USE FUNCTIONS WHICH DON’T REQUIRE ANY LOGGING IN
What is Glitch.com?
Glitch.com is a free hosting service which allows us to keep our bots on a webserver.Why do I need to use Glitch?
Well if say you wanted a ranking bot it wouldn’t be very good if it was running on your computer as it would be very hard to access. However with Glitch we can put that bot on a website and can then call it through HTTP Service. It is also great as you can get Roblox resources directly via get/post request which is something you can’t do in the game itself.
Getting Started
So first thing you need to do I go on to glitch.com and create an account. After that it would look a bit confusing however all you need to do is go up to the search bar next to New Project
type in “hello-express” and hit enter. Once you have done that you should see I a few results however press the first one with blue and red on.
After you have clicked it scroll down to where it says remix your own.
As soon as you press that it’s coding time.
The bits that make it work
So first thing you want to do is go to the server.js file press ctrl+a then delete.
After go to package.json and at the top where it says add package just click that type in noblox.js and the first one is all you need.
So now your code should look like this:
Apart from some version numbers and node type.
Finally go over to the public folder and where it says client.js press the 3 dots on the right of it and then delete.
Coding Time
Starting Express
So first thing first we need to start the app. We can do this by doing
const express = require("express")
const app = express();
app.use(express.static("public"));
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});
The listener bit is required and your website will not update without it!
This is a start but now we need to get the certain urls working. So we can do:
const express = require("express")
const app = express();
app.use(express.static("public"));
app.get("/", function(req, res) { //req and res just mean response and request we can get onto them later
res.send("Hi") //This will return Hi
});
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});
and if we got to our page by pressing preview then “in new window” or as a preview pane it will show:
but we don’t want it just to show “Hi”.
Using Noblox.js
We want it to show/do roblox interactions so let’s just put this a side for a second. Now you could use axios for this but I will be making a different tutorial on that instead we will be using the wrapper noblox.js. It should already be installed in the package.json folder meaning we can do:
const noblox = require("noblox.js")
I suggest taking a look through the documentation as it is really helpful
So for the first bit we a going to make something which checks if a user owns an asset. We can do this by calling the getOwnership function
const noblox = require("noblox.js")
let ownership = noblox.getOwnership(1, 1402432199) // first bit is user id second is item/asset id and can be a third which is type of asset
console.log(ownership)
(You can view the console in glitch by pressing a button that says logs)
You should of gotten this response:
Promise { <pending> }
this is a good thing as it means that our app is working and noblox is doing it’s thing.
To fix this all we need to do is add they key word await this is so the program knows to not return anything until the promise has been returned however await has to been inside an async function so your could would look like this instead:
const noblox = require("noblox.js")
async function Start(){
let ownership = await noblox.getOwnership(1, 1402432199) // first bit is user id second is item/asset id and can be a third which is type of asset
console.log(ownership)
}
Start()
You should receive an output of true
There is another way however we can do this. As it is a promise we can use a .then
function which will call when a value is defined meaning your code could also look like this:
const noblox = require("noblox.js")
async function Start(){
let ownership = noblox.getOwnership(1, 1402432199) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
})
}
Start()
That should also say true. We can take this 1 step further aswell because if this function errored because we ran it to much then it would break the rest of the script however we can use the .catch
function which is like a pcall
in lua or just a function that when errored will not let anything else break.
Now your code could look like this:
const noblox = require("noblox.js")
async function Start(){
let ownership = noblox.getOwnership(1, 1402432199) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
}).catch(function(error){
console.log(error)
})
}
Start()
Multiple functions
Say I wanted to do this twice but at different times then instead of making 2 separate projects we can use the different urls bit from earlier and so now we could do:
const express = require("express")
const app = express();
app.use(express.static("public"));
const noblox = require("noblox.js")
async function GetValk(){
let ownership = noblox.getOwnership(1, 1402432199) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
}).catch(function(error){
console.log(error)
})
}
async function GetDominus(){
let ownership = noblox.getOwnership(1, 48545806) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
}).catch(function(error){
console.log(error)
})
}
app.get("/Valk", function(req, res) {
GetValk()
res.send("Hi") //This will return Hi
});
app.get("/Dominus", function(req, res) {
GetDominus()
res.send("Hi") //This will return Hi
});
Accessing the url
So now pressing the preview in a new window button in the should bring up the page in the url after it says .me type either /Valk or /Dominus
Now once the page loads you might find that it is still saying “Hi” we don’t want this as HttpService won’t work so instead we need to make the functions return a value all we need to do is put return infront of response so:
async function GetValk(){
let ownership = noblox.getOwnership(1, 1402432199) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
return response
}).catch(function(error){
console.log(error)
return "Error"
})
}
async function GetDominus(){
let ownership = noblox.getOwnership(1, 48545806) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
return response
}).catch(function(error){
console.log(error)
return "Error"
})
}
Sadly that wouldn’t work so instead we have to revert a bit back to our old code so can do:
async function GetValk(){
let ownership = noblox.getOwnership(1, 1402432199) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
}).catch(function(error){
console.log(error)
return "Error"
})
return ownership
}
async function GetDominus(){
let ownership = await noblox.getOwnership(1, 48545806) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
}).catch(function(error){
console.log(error)
return "Error"
})
return ownership
}
Now that the functions return something in the url bits we can do:
app.get("/Valk", function(req, res) {
let Result = GetValk()
res.json(Result) //This will return if they have the valk
});
app.get("/Dominus", function(req, res) {
let Result = GetDominus()
res.json(Result) //This will return if they have the Dominus
});
All the code together:
const express = require("express")
const app = express();
app.use(express.static("public"));
const noblox = require("noblox.js")
async function GetValk(){
let ownership = noblox.getOwnership(1, 1402432199) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
return response
}).catch(function(error){
console.log(error)
return "Error"
})
}
async function GetDominus(){
let ownership = noblox.getOwnership(1, 48545806) // first bit is user id second is item/asset id and can be a third which is type of asset
.then(function(response){
console.log(response)
return response
}).catch(function(error){
console.log(error)
return "Error"
})
}
app.get("/Valk", function(req, res) {
let Result = GetValk()
res.json(Result) //This will return if they have the valk
});
app.get("/Dominus", function(req, res) {
let Result = GetDominus()
res.json(Result) //This will return if they have the Dominus
});
//And don't forget the important bit!
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});
Finished?
Now you might be thinking what about functions which require you to log in with cookies. Well this is already an EXTREMELY long tutorial so if you read it all so I shall be doing that on a different post very soon. Anywhere you basically already there I am sure in a few days you would know how to.
Thank you and any questions please post down below also do account for any limits on glitch and noblox