So I’m trying to create a bot that automatically ranks people in my Roblox roleplay game, and in order to do so, I created a user API in Roblox, then created a cloud flare worker to post to that API, and then my game posts to that cloud flare API. But it always prints out in cloud flare workers “ROBLOX RESPONSE 400 { “code”: “INVALID_ARGUMENT”, “message”: “Failed to parse resource path and its identifiers - .” }”
Here’s my cloud flare worker code
export default {
async fetch(request, env) {
try {
if (request.method !== "POST") {
return new Response(
JSON.stringify({
success: false,
error: "Method not allowed"
}),
{
status: 405,
headers: {
"Content-Type": "application/json"
}
}
)
}
const body = await request.json()
const userId = body.userId
if (!userId) {
return new Response(
JSON.stringify({
success: false,
error: "Missing userId"
}),
{
status: 400,
headers: {
"Content-Type": "application/json"
}
}
)
}
const GROUP_ID = 0
const PRISON_GUARD_ROLE_ID = 0
console.log("USER ID:", userId)
console.log("GROUP:", GROUP_ID)
console.log("ROLE:", PRISON_GUARD_ROLE_ID)
console.log("API KEY EXISTS:", !!env.ROBLOX_API_KEY)
const robloxResponse = await fetch(
`https://apis.roblox.com/cloud/v2/groups/${GROUP_ID}/memberships/${userId}`,
{
method: "PATCH",
headers: {
"Content-Type": "application/json",
"x-api-key": env.ROBLOX_API_KEY
},
body: JSON.stringify({
roleId: PRISON_GUARD_ROLE_ID
})
}
)
const responseText = await robloxResponse.text()
console.log(
"ROBLOX RESPONSE",
robloxResponse.status,
responseText
)
return new Response(
JSON.stringify({
success: robloxResponse.ok,
status: robloxResponse.status,
body: responseText
}),
{
status: robloxResponse.status,
headers: {
"Content-Type": "application/json"
}
}
)
}
catch (err) {
return new Response(
JSON.stringify({
success: false,
error: err.toString()
}),
{
status: 500,
headers: {
"Content-Type": "application/json"
}
}
)
}
}
}
