Can't Parse JSON Error when using Trello API

I’m currently trying to make an application game connected to Trello via @nstrike159’s Trello API and I was just testing the Trello API before writing the rest of the code, but I keep getting the “Can’t Parse JSON” error when I attempt to get the BoardID. I’ve marked where the errors are below.


My Code:

local api = require(game.ServerScriptService:WaitForChild("TrelloAPI"))
local board = api:GetBoardID("2019") --Error here, nothing past here runs
local pending = api:GetListID("Pending Applications",board)
local card = api:AddCard("Card Name","Card Description",pending)

API’s Code:

function T:GetBoardID(name)
   local url
   if Private then
      getAddon()
      url="https://api.trello.com/1/members/me/boards"..addon
   else
      getAddon()
      url="https://api.trello.com/1/members/me/boards"..addon
   end
   local tball=HS:GetAsync(url,true)
   local dt=HS:JSONDecode(tball) --Error here
   for _,tab in pairs(dt) do
      for p,it in pairs(tab) do
         if p=="name" and it==name then
            return tab.id
         end
      end
   end
   error(name.." not found!")
   return nil
end

I’ve used his Trello API many times before and never had any issue, but I’ve never worked with HttpService so I’m not sure what the issue is.

2 Likes

Print the raw JSON and verify it’s valid / not empty / contains clues. It’s possible you’re getting back an error or something instead of JSON.

What is getAddon() and addon?

2 Likes

Could potentially be any of these:

  • HttpService is not enabled
  • You have insufficient credentials to access the board (do you have a token and/or API key set up for private board access?)
  • The method is not being called properly (as it is, don’t even know what’s in your console)
  • Invalid arguments are being passed to each method
  • The script is outdated and not using latest API docs
1 Like

From the code you gave us, I don’t see addon being defined anywhere. You should also check if addon starts with a / as well otherwise your url is formatted incorrectly.

1 Like

Thanks for bringing that up, I didn’t think to print it. It printed “invalid key” so that narrowed it down. The issue was that for some reason it wasn’t getting the key, so I just had to manually changed the key. I was able to fix it though, so thanks!

Glad you figured it out. Remember to mark a solution for this thread.

1 Like