Why is HttpService:RequestAsync() suddenly returning nil?

Hi! I was accessing the Notion API when suddenly RequestAsync() started returning nil.

Could somebody help me please?

Here’s my code:

local nuuh = {["token"] = "secret_gftufuFU6yhgyFG68F7YghGFygHggg"}

local HttpService = game:GetService("HttpService")
local APIVersion = "2022-06-28"
local APILink = "https://api.notion.com/v1"

local buildQuery = require(script.QUERY_STRING_BUILDER).buildQuery

function nuuh.getUsers(page_size: number | nil, start_cursor: string | nil)
	local success, response = pcall(function()HttpService:RequestAsync(

		{
			Url = string.format("%s/users/%s", APILink, buildQuery({page_size, start_cursor})),
			Method = "GET",
			Headers = {
				["Authorization"] = "Bearer " .. nuuh.token,
				["Notion-Version"] = APIVersion
			}
		})
	end)
	print(success, response)
	return response
end
2 Likes

You should use print statements to ensure that you’re sending to the correct endpoints.

Also, do you mean that it worked before and now it doesn’t?

2 Likes

Yes, it worked but now it doesn’t.
I know that it’s not the endpoint being down or anything because I can open it in my browser.

1 Like

I’m not familiar with the Notion API, but one common reason for this sort of thing to happen is because the token expires. I don’t know how you’re retrieving the token, but to test this theory out, try retrieving a new one and use that in place of the current one. If everything starts working again with no additional changes, we can identify the token as the issue. If it’s still nil, we can work from there.

2 Likes

It still doesn’t work.
Also, if my token was invalid, it would error with unauthorized.

1 Like

Have you tried running the request in another setting? Postman, cURL, axios, etc. If not you should. See if the results you’re getting are the same.

Also, if we assume that an unauthorized (403) request would return an error, then we can also assume that any 400 level request would return an error. This further implies (correct me if I’m wrong) that since your system is not erroring, it’s probably returning a 200, meaning that maybe it’s the data itself that you’re retrieving that’s resulting nil? Perhaps ensure that the data itself is not nil (i’m sure you already have but maybe one more time).

2 Likes

You’re not returning the web request result inside the pcall’ed function, add a return statement to fix it:

--...
local success, response = pcall(function()
   return HttpService:RequestAsync(
--...
4 Likes

I know that it’s not the endpoint being down or anything because I can open it in my browser.

I am going to scream, really badly.
Why did this work earlier??
Did I just waste my whole day googling things???

Life is good, and life is well.

thanks yall

1 Like

Maybe Roblox servers had/have issues with HttpService? Check now, not sure if its fixed now though

Please do not reply to posts without reading already proposed solutions.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.