Open OCR API code needs fixing

Hi Thunkers!
Today I tried using the Open OCR API(the one @jacob1 used in his barcode scanner ), and that crashes the app.
Here’s my code:

The camera and media db are working fine(these are used to get the image to send to OCR).
Any suggestions on how to fix this code?

1 Like

What error/result are you getting @codeswept? (i.e can you try it without the if/else logic, and just use labels?)

Are you able to connect to the API in your browser or Postman?

1 Like

If you can send the response text of the API as I think the crash is due to the blocks of the JSON response not being in order.


This is my error:

Yes @domhnallohanlon this gave me a response on my browser. I put it into and then coded my JSON. Sure @muneer, I’ll send my response text as soon as I get on my laptop. I’m currently on my tablet.

When troubleshooting an API call, I would want to know this:

Can you get a valid JSON response by pasting the full API url into a browser?

If so, post the full url here (removing the API key first).

If so, post the full JSON response here (hiding any private/confidential data).

The next step would be to see your blocks, which you’ve posted above, and see if the property values match the JSON structure. If they don’t, or if you have any spelling/case errors, you’ll get a white screen which is now replaced by the “Something has gone wrong” message you saw.

1 Like

I do get a valid JSON response in my browser.

When put in

The URL is
I got the image in the URL from Google.

Your blocks look correct to me for that JSON response. Are you just assigning a label’s text value to “app variable ocr text” or is there more going on than that?

1 Like

This works for me (the url is the same as you posted but with my own API key):

It displays this:


1 Like

No, nothing different.

Are you saying it still doesn’t work for you? Do you want to send me the link to your project? I can use my own API key to see if it works with your code. You’ll have to let me know which screen it’s on, etc.

1 Like

I can send you via PM. Earlier, I was using camera to allow users to take their own pictures, but now I’m trying to replace it with an image from the net.

I see. Sure. I might go to sleep in a little bit but I’ll take a look soon.

1 Like

I’ve sent you the link. Even after I’ve replaced the Image URL with something from Google I still get an error.
Edit: It’s working after I removed the Camera and Media DB code. I think it had something to do with that. I got the correct text in my input after removing those.

Okay because when I checked it, I just needed to connect the “app variable ocr text” to the label block. You must have fixed it before I accessed your link.

Glad it’s working at least so far!

1 Like

It’s not working as soon as I add the camera code again. Can you drag it(it’s unconnected code beside the main code) back into place and then try it?

I think you’d have to share a new link. I’m only seeing this:

Sorry for the late reply. I’ll share the new link via PMs, but I think that unconnected blocks are automatically deleted when shared. Regardless, I’ll share the link.

One way I like to troubleshoot complex blocks like this is to add a “report and wait” function to display text in a label for each step:

When I preview those blocks in Thunkable Live, I see this:



So it never gets to STEP 5 which means that the problem occurs right before that:


But it’s unlikely that text input assignment is actually causing the problem so I’m thinking it’s actually the JSON parsing. But why? That I don’t know yet.

I do know that if there’s no value in the ParsedText property of the JSON response, the app will crash.


It’s worth removing the variable ocr text and just add your own simple text and see if it will still crash. As you said this is unlikely but let’s not keep a single stone unturned.

That’s a great idea! Will do it and let you know the results.