Returning as nil

I am trying to get the UniverseId, using a module so the link is valid (Fixing HttpService: Make PUT, PATCH, DELETE requests, access response headers, proxy to any site, and more). It works, but once I try to get the universeId from the body, it returns as nil

image

when it the actually body looks like this:
image

I do admit, I am new to httpservice, so wont know a lot. Am I making a rookie mistake? How can I get the UniverseId?

Code:
image

Can you please put your code into code block, because this not comfort to see and edit something.

Sure, my bad

local ProxyService = require(game:GetService('ServerScriptService').ProxyService)
local Proxy = ProxyService:New('') --removed the key, shouldn't change anything


local body = Proxy:Get('https://api.roblox.com/universes/get-universe-containing-place?placeid=402122991').body

print (body)
print (body.UniverseId)

Can you print out whole response? Not only body

You’re forgetting to Decode the JSON, You need to use HttpService:JSONDecode on the Body

local HttpService = game:GetService("HttpService")
local ProxyService = require(game:GetService('ServerScriptService').ProxyService)
local Proxy = ProxyService:New('') --removed the key, shouldn't change anything

local body = HttpService:JSONDecode(Proxy:Get('https://api.roblox.com/universes/get-universe-containing-place?placeid=402122991').body)

print (body)
print (body.UniverseId)

Although can’t you just use HttpService immediately?

local HttpService = game:GetService("HttpService")

local body = HttpService:JSONDecode(HttpService:GetAsync('https://api.rprxy.xyz/universes/get-universe-containing-place?placeid=402122991'))

print (body)
print (body.UniverseId)

rprxy.xyz is required instead of roblox.com since you can’t use Roblox.com apis using Roblox itself, rprxy.xyz is just a proxy

Oh. I actually got why it happens. Response body is a JSON. You must convert it.

body = game.HttpService:JSONDecode(body)

image

Alright, I’ll try that and get back to you

1 Like

image

If I may ask, what is the current code that you have?

remove .body on end from local body

I have already done that and the error still came up

Show current code, then please.

The module or the script I am using right now?

That script that you are using right now that is erroring

local ProxyService = require(game:GetService('ServerScriptService').ProxyService)
local Proxy = ProxyService:New('')


local body = Proxy:Get('https://api.roblox.com/universes/get-universe-containing-place?placeid=402122991')
body = game.HttpService:JSONDecode(body)
print (body)
print (body.body.UniverseId)

Try this?

local ProxyService = require(game:GetService('ServerScriptService').ProxyService)
local Proxy = ProxyService:New('')


local body = Proxy:Get('https://api.roblox.com/universes/get-universe-containing-place?placeid=402122991')
body = game:GetService("HttpService"):JSONDecode(body.body)
print(body)
print(body.UniverseId)
1 Like

Yeah, my bad. This should work.

2 Likes

That works, thank you so much and also @Diltz_3

2 Likes

Don’t forget to mark solution.