Hey, everybody! I was working on an OCR and it was working fine for a few weeks. Then when I checked again yesterday it stopped working. When I copy paste the WEB API url into google, it works fine. But when I call the web API “get” function, it outputs «””». I don’t know what the problem is, because I did not change the code.
We’re going to need more information than that…
Post a screenshot of the blocks you’re using. It’s possible that the API changed its JSON format and your blocks no longer parse the JSON correctly.
Most APIs return JSON formatted data in the green “response” block. So you’d want to use the “get object from JSON” block not the “generate JSON from object” block. In all honesty, it took me a long time to understand the difference between those two blocks.
If that doesn’t fix the problem or if your API response is not JSON, I have two other suggestions:
- Check the green error block to see what value, if any, it’s returning.
- Send me the full API URL in a private message and I’ll see if I can figure out what’s wrong.
Edit: according to their documentation, the API returns JSON, as I assumed.
Another reminder is to be sure to run it from the mobile Live Test app not the Web Live Test.
I have tried changing the “generate JSON from object response” to “get object from JSON response”, but it is still not working. It outputs “null”. I have also tried seeing the value of the error block but it says it is undefined. I have sent the full web api url in private messages.
Hi there,
You can use the green ‘error’ block to say
if [error]
set Text_Input's Text to error
else
{whatever you want to do with the response}
This will help you identify if the issue is with your API call.
The response will be in JSON, so you can start by printing the full JSON response on a Label. If that works, convert the JSON to an object and get a property of it.
I tried that and it says “network request failed”.
This means you are running a code with API using Web Live Test. Use the mobile Live Test app and this error should disappear.
Those were the responses I got when using the Live Test app
Then, you need to test your URL from a system outside of Thunkable like direct with the browser or using postman.
Here is the thing, when I insert the web API url into google, it shows the parsed text. But when I ask for the “stored variable” (you can see it in my blocks at the top), it returns «””».
Go back to your initialize block and give a name to your stored variable. Currently it has no name and you can not reference it.
Give the stored variable a name and then use that name in the API block.
So, I made a new project in thunkable and used the same code. The OCR works in the new one, but it does not work in the old one. Do you happen to know why?
Nope. That’s the challenge of coding something… the smallest mistake can break something. And it could be anything… a space where there shouldn’t be one, a conflicting variable name, a text string when a function is expecting an integer, etc.