Roblox External Database API |

Here you will find an API that allows you to easily play around with as a database:

Notice: This API uses a Heroku Proxy Service. I currently use a free one created by Sentanos; you can find it here: I won’t go too much into detail about this but all you need from this is the url and the access key (which you can find in the config vars).

Anyways, here’s some documentation on this API.

local rest_db = require(game:GetService("ServerScriptService").RestDB)

rest_db:SetDBUrl(string DatabaseName) -- for example, "roblox"; you do not need to put the full url, just the name of your database
rest_db:SetDBKey(string DatabaseAPIKey) -- for example "123456789", you can find this key in Developer Mode on
rest_db:SetProxyUrl(string ProxyUrl) -- for example, ""
rest_db:SetProxyKey(string ProxyKey) -- for example, "123456789"; found in config vars on Heroku
rest_db:InitProxy() -- you must run this after setting your url and key

Now that we’ve set it up, we can do something like getting a collection:

rest_db:GetCollection(string CollectionName) -- for example, "users"

This will return all of the documents inside the collection, if you do not have any documents inside, or the collection does not exist, you will receive an error.

You can add documents to a collection:

rest_db:AddDocument(string CollectionName, table DocumentFields)
-- for example:
rest_db:AddDocument("users", {["name"] = "xJDiviisionZ"})
-- will create a document with the body: {"name": "xJDiviisionZ"}
-- note: this function WILL return the document too, so
-- you can use variables to define this document so you can
-- retrieve it later
-- for example:
local new_doc = rest_db:AddDocument("users", {["name"] = "xJDiviisionZ"})
-- say you wanted to delete this document:
rest_db:DeleteDocument(string CollectionName, string id)
-- therefore
rest_db:DeleteDocument("users", new_doc._id)
-- note: it MUST be _id not id - simply the way is setup

You can also update a document:

local new_doc = rest_db:AddDocument("users", {["name"] = "xJDiviisionZ"})
local updated_doc = rest_db:UpdateDocument("users", new_doc._id, {["name"] = "xjdiviisionz"})
-- again, :UpdateDocument() ALSO returns the document
-- allowing you to use variables to store the document for later use

I know I already showcased this but just to be clear on everything covered, you can also delete documents:

local new_doc = rest_db:AddDocument("users", {["name"] = "xJDiviisionZ"})
local updated_doc = rest_db:UpdateDocument("users", new_doc._id, {["name"] = "xjdiviisionz"})
rest_db:DeleteDocument("users", updated_doc._id)

Finally, you can verify a collection (whether it is empty or exists) by doing:

local collection = "users"
local ver = rest_db:Verify(string CollectionName)
if ver then
    print(collection.." exists.")
    print(collection.." is either empty or does not exist.")

You’ve got a typo here; your brackets are enclosing the entire table.

Looks good, but can I ask: why are you using a proxy to access the site?

Thanks for pointing this out ^ also I use a proxy because when I don’t, I get an error along the lines of trust check failed.

Ah fair enough. That makes sense! Looks like you’ve done a good job with this anyway. I didn’t know about, but it looks like a great resource I may consider using, even if it’s for off-Roblox projects.

Thank you and yes, it was weird working with it because until recently, I was unknown to HttpService and I had been using mongodb for things like discord bots (since Heroku doesn’t work with .json files for storage). However, mongodb requires it’s own module and they removed API keys so I had no other way to access the database. I currently use to send message data to my discord bot. The bot then gets the data from and sends a message in the discord.

That seems like a good use for this. It’ll be great just for prototyping too. I have an old mLab (which was purchased by MongoDB) account, which still has access to the REST API, so that’s something I use sometimes too.

it dosnt seem to work? Is the a problem with my code?

local rest_db = require(script.Parent.MainModule)

local DatabaseName = "hazestudiospremium"
local DatabaseKey = Private

local ProxyURL = ""
local ProxyKey = Private

local CollectionName = "Users"



local Verify = rest_db:Verify(CollectionName)
if Verify then print(CollectionName .. " exists!") else print(CollectionName .. " dosnt exist") end

if Verify then
     local DocumentData = {["name"] = "deadwalker601"}
     local Doc = rest_db:AddDocument("users", DocumentData)

It alwasy prints that the collection dosnt exist