# Open OCR API code needs fixing

**URL:** <https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107>\
**Category:** Questions about Thunkable X\
**Created:** [February 22, 2021, 1:55pm UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107 "2021-02-22T13:55:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 22, 2021, 1:55pm UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/1 "2021-02-22T13:55:36Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/4/a4c2e6e00389ed7561b1801416fa636f9ec231c9.png)  
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?  
Thanks

---

<div class="post-metadata">

**Author:** ![domhnallohanlon](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/domhnallohanlon/32/29554_2.png) [@domhnallohanlon](https://community.thunkable.com/u/domhnallohanlon)\
**Post date:** [February 22, 2021, 4:27pm UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/2 "2021-02-22T16:27:33Z")

</div>

> [@codeswept](#):
>
> Any suggestions on how to fix this code?

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?

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [February 22, 2021, 4:41pm UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/3 "2021-02-22T16:41:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 23, 2021, 2:45am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/4 "2021-02-23T02:45:21Z")

</div>

This is my error:

 ![Screenshot_20210223-081117_Thunkable](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/0/f03f6c2bfdc2d5ff895b4ce53fdaca6a58fdf469.jpeg)  
Yes @domhnallohanlon this gave me a response on my browser. I put it into [jsonformatter-online.com](http://jsonformatter-online.com) 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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 23, 2021, 6:43am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/5 "2021-02-23T06:43:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 23, 2021, 9:55am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/6 "2021-02-23T09:55:03Z")

</div>

I do get a valid JSON response in my browser.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/5/05b2cdb10843df920a213599001f1aae4b971080.png)  
When put in [jsonformatter-online.com](http://jsonformatter-online.com):  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/a/9aed7b3d1f647a8e6e3119f7bf5eecf32975aef9.png)

The URL is [https://api.ocr.space/parse/imageurl?apikey=MY\_API\_KEY&url=https://i.stack.imgur.com/vrkIj.png](https://api.ocr.space/parse/imageurl?apikey=MY_API_KEY&url=https://i.stack.imgur.com/vrkIj.png)  
I got the image in the URL from Google.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 24, 2021, 7:43am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/7 "2021-02-24T07:43:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 24, 2021, 7:52am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/8 "2021-02-24T07:52:25Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/0/b0d9c0a9fbdbe1aa6b60d166c9152b52c61d2550.png)

It displays this:

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/e/de7bba94a34e49c3bad83eb34bf617ce03d1a936.png)

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 24, 2021, 7:56am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/9 "2021-02-24T07:56:49Z")

</div>

No, nothing different.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 24, 2021, 7:58am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/10 "2021-02-24T07:58:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 24, 2021, 7:59am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/11 "2021-02-24T07:59:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 24, 2021, 8:00am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/12 "2021-02-24T08:00:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 24, 2021, 8:02am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/13 "2021-02-24T08:02:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 24, 2021, 8:08am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/14 "2021-02-24T08:08:22Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 24, 2021, 8:10am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/15 "2021-02-24T08:10:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 24, 2021, 8:14am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/16 "2021-02-24T08:14:36Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/b/dbf691dd4148092f28fe3c1f5f6c226adcb29d48.png)

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 25, 2021, 4:14am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/17 "2021-02-25T04:14:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [February 25, 2021, 7:21am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/18 "2021-02-25T07:21:20Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/5/65fb0484bf589e93a5e319178fff0aef13135ef6.png)

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

STEP 1  
STEP 2  
STEP 3  
STEP 4

[crash]

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

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/1/f1d8fe879a9ababd9a4562f7581dccd937fd1831.png)

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.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [February 25, 2021, 8:30am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/19 "2021-02-25T08:30:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codeswept](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/codeswept/32/87755_2.png) [@codeswept](https://community.thunkable.com/u/codeswept)\
**Post date:** [February 25, 2021, 9:53am UTC](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107/20 "2021-02-25T09:53:15Z")

</div>

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

[Next page](https://community.thunkable.com/t/open-ocr-api-code-needs-fixing/1116107.md?page=2)
