How do I set an optionnal value for functions without having the "cannot convert string into string?" warnings?

Hello! The title says it all.
I want to do this because I’m creating a SDK for the Notion API.

I can’t find anything online.

Here’s my code:

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

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

-- deleted this cuz too long and not needed
nuuh.options = {}
local function encode(str, legal)
end
local function buildQuery(tab, sep, key)
end

function nuuh.getUsers(page_size: number?, start_cursor: string?)
	local success
	local response


	success, response = pcall(HttpService:RequestAsync(

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

end

return nuuh

thanks

(Ill have a look at what your questionis asking in a moment, but you should remove any API keys and secrets from code before posting it here)

oh yeah that’s not my key i smashed my keyboard

Found the solution 5 mins after posting:

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


	success, response = pcall(HttpService:RequestAsync(

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

end

I could just add a | and nil after that.
It means number or nil

EDIT: Sorry to the person who was writing a lengthy response, saw you writing.

life is good

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