Bubble API & Roblox API

Hello all! I have a script in Roblox that communicates with Bubble.io API and creates a new database entry if certain conditions are met. However, everytime I join the Roblox server I get a error code saying that the API is a 400:Bad Request. I am using the API link under API settings in Bubble. How do I fix this?

Share your API connector settings please


I don’t even know how to setup it up properly :confused:

From where do you get the 400 error? You didn’t configure anything in API Connector

I got the 400 error when putting the Bubble.IO API url into the roblox script. When I try to run the script I get that error code

Sorry, didn’t understand what you mean at first and was thinking you was calling Roblox API.
400 error mean your request is not correctly set. Please share your request/script in Roblox
Also, did you activate Backend WF / Data API ?
If you have a Backend WF, share the settnig too with the endpoint you are calling

Sure thing. This script is supposed to scan for all users who join the game. If their roblox ID does not match the “student_id” in the Bubble.IO database, then it will create a new Bubble database entry.

local HttpService = game:GetService(“HttpService”)
local Players = game:GetService(“Players”)

local bubbleAPI = “https://www.c-ischools911.org/version-test/api/1.1/obj/studentdata
local apiKey = “ffba9b296cdf302f56333109cac00561” – Replace with your actual API key

function checkPlayerInDatabase(player)
local playerID = player.UserId
local requestUrl = bubbleAPI … “?sid=” … playerID

-- Send request to Bubble.io API to check if player exists
local success, response = pcall(HttpService.GetAsync, HttpService, requestUrl)

if success then
	local data = HttpService:JSONDecode(response)
	if data.exists then
		print("Player exists in database, script cancelled.")
	else
		-- Player doesn't exist, create new entry
		createNewDatabaseEntry(playerID, player.Name)
	end
else
	warn("Failed to check player in database:", response)
end

end

function createNewDatabaseEntry(playerID, playerName)
local requestData = {
sid = playerID,
legal_name = playerName
}

-- Send request to Bubble.io API to create new entry
local success, response = pcall(HttpService.PostAsync, HttpService, bubbleAPI, HttpService:JSONEncode(requestData), Enum.HttpContentType.ApplicationJson, false, {["X-API-Key"] = apiKey})

if success then
	print("New database entry created for player:", playerName)
else
	warn("Failed to create new database entry:", response)
end

end

– Event handler for when a player joins the game
Players.PlayerAdded:Connect(checkPlayerInDatabase)

request url is not encoded correctly.
Is the player.UserId is the Bubble unique ID?
Are you trying to do a kind of search to get list of user with playerID?

So basically what I am trying to do is scan the entire studentdata database. The script is supposed to run on a player joining the game. Upon the player joining, if their roblox ID matches the “sid” or studentid, then the script is cancelled and doesn’t continue any further. However, if the “sid” doesn’t match any records, then the script should continue to create a new record with the players Roblox ID as the “sid”.

Hey just checking in to see if you have any update for me. I’ve been trying and I don’t know what im doing wrong

is the sid = the unique_id in Bubble user DB?

No, the sid = a text value

So you have two options
A) using Workflow API with return data
B) using Data api with constraints Data API requests | Bubble Docs | Data API requests | Bubble Docs

I’m going to be completely honest with you and idk what either of those mean. Whichever one would help me achieve this the best way possible would be awesome. Just trying to make this script so I can better my game. I will take all the help and advice you will give.