Hi there, I’m trying to learn API’s. But I got this issue, that I can’t seem to fix.
At line 20, it says that it can’t parse JSON. Here’s the script.
-- Server Script
local http = game:GetService('HttpService')
local api_key = '********************************' -- API key
local url = "https://developer.schiphol.nl/admin/applications/1409623844995"
local headers = {
["Authorization"] = "Bearer " .. api_key,
}
game:GetService("Players").PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message:lower() == "!getdata" then
local response = http:RequestAsync({
Url = url,
Method = "GET",
Headers = headers
})
if response.Success then
local responseData = http:JSONDecode(response.Body)
print(responseData)
else
print("Failed to make the request:", response.StatusMessage)
end
end
end)
end)
I’m not sure if the url is correct though. I just copied the link of the tab.
Apart from that, what’s an application ID?
You seem to be accessing a webpage instead of an API.
You should check schiphol’s documentation—there should be a URL they tell you to use. I don’t have access to their API and don’t want to make an account, but ChatGPT tells me you’re looking for something that starts with https://api.schiphol.nl/ (e.g. https://api.schipol.nl/public-flights)
ChatGPT lies sometimes though, so check their documentation to confirm.
This is data about the API. I also changed the script to this
local app_id = 'b25ac413'
local app_key = '*******************************' -- API key
local url = "https://api.schiphol.nl/public-flights/flights?includedelays=false&page=0&sort=%2BscheduleTime"
local headers = {
["Accept"]= "application/json",
["app-id"]= "b25ac413",
["app-key"]= "*******************************"
["ResourceVersion"]= "v4"
}
-- The rest is the same
Were you not supposed to put a comma (,) at the end of your app-key header value? Can’t see any issues apart from that right now.
Additionally, if you’re adding the app-id and app-key in the header anyway and not the variables at the top there, you can remove the top two lines of that header snippet you sent.