# How to create nutrition app with ocr scanner?

**URL:** <https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955>\
**Category:** Questions about Thunkable X\
**Created:** [February 21, 2021, 5:28pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955 "2021-02-21T17:28:00Z")\
**Posts on this page:** 20\
**Page:** 5

<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:** [March 5, 2021, 4:53am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/82 "2021-03-05T04:53:24Z")

</div>

If the “error” block has a value, you generally shouldn’t proceed with the next steps because it will likely result in the app crashing or other unpredictable behavior.

In the tutorial video I made, I show how to use an if/then block to check that value.

But a simple way to check it is to assign the “error” block to a label’s text and see what the result is.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 5, 2021, 12:57pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/83 "2021-03-05T12:57:20Z")

</div>

This is what it says in the error box:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/8/88516b4f7b03e5ec1df206456ecf6b487bfc7aec.jpeg)

---

<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:** [March 5, 2021, 1:28pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/84 "2021-03-05T13:28:05Z")

</div>

Ohhh… you should live test it on your device

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 5, 2021, 1:33pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/85 "2021-03-05T13:33:56Z")

</div>

Okay thank you it worked on my phone! But when the barcode scanner opens on my phone, it goes onto a different camera but doesn’t let me take a picture or scan anything.

---

<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:** [March 5, 2021, 2:22pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/86 "2021-03-05T14:22:10Z")

</div>

Yes it does. When you pass the camera over a barcode it automatically captures the barcode.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 5, 2021, 2:23pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/87 "2021-03-05T14:23:41Z")

</div>

Okay I’ll try again

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 5, 2021, 8:31pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/88 "2021-03-05T20:31:43Z")

</div>

I’m trying to get the nutriscore so I put in the positive and negative points but when I scan it just says “undefined”.

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

---

<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:** [March 6, 2021, 12:36am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/89 "2021-03-06T00:36:38Z")

</div>

Why are you setting Main’s Text to app variable json response? You should be setting that label’s text to the “get property of object blocks.”

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 6, 2021, 5:19pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/90 "2021-03-06T17:19:41Z")

</div>

I was trying to mess around with the status numbers but I’m not sure which is the right number, so I can get the actual value. Right now I get the value “0”. So what numbers should I put in there? I’m trying to get the nutriscore which is like gthe food a grade (A,B,C,D,E). And I think that the positive and negative points will help me get that. So what do I need to change in order to get that the food grade?

This is what I have so far:

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

---

<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:** [March 6, 2021, 6:29pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/91 "2021-03-06T18:29:02Z")

</div>

You can Google _API status codes_ to learn more about them. A status of “200” is a successful connection to the API server. You should only be checking to see if status equals 200. If it doesn’t, then something went wrong and you probably have a value in the green error block.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 6, 2021, 6:45pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/92 "2021-03-06T18:45:10Z")

</div>

I made the status 200 but it still says “0” in the label. Would I have to change the properties to get the nutriscore or food grade(A,B,C,D,E)?

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

---

<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:** [March 6, 2021, 7:24pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/93 "2021-03-06T19:24:00Z")

</div>

How do you know that that’s wrong? If you get **any** value back from a JSON object then you parsed it correctly. 🙂 I just checked a barcode and its “positive\_points” value is zero, for example.

If you want other property values then you have to figure out the “path” / hierarchy to those properties. You can re-watch my video if it’s helpful to understand that better.

The one thing I would recommend for you is that you ignore the “status” block. Just check if the green “error” block has a value and if not, start putting values into labels. Because the way you have it set up, it’s only going to check the “negative\_points” property if the status is **not** 200.

You also need to figure out what kind of information you’re getting from the JSON data and how you’re going to display it. It looks like your intention was to display both the positive\_points and negative\_points in the same label at the same time. That’s not going to work because as soon as you assign a value to a label, it replaces the old value.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 6, 2021, 9:49pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/94 "2021-03-06T21:49:37Z")

</div>

I created two different labels for the positive and negative points. But I’m not sure what other properties would be needed to get the food grade. This screenshot shows how to calculate and get the food grade, but I don’t know which property would incorporate this as the result.  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/b/1b72a9d9d787a4b88edae136d875b9cb2dc8937c.png)

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 7, 2021, 1:22am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/95 "2021-03-07T01:22:59Z")

</div>

I added some more blocks and values. Is this correct?

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

---

<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:** [March 7, 2021, 2:18am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/96 "2021-03-07T02:18:06Z")

</div>

> [@celebytes20212iy4](#):
>
> This screenshot shows how to calculate and get the food grade, but I don’t know which property would incorporate this as the result.

I have no idea, either. I don’t know anything about the API you’re using. It may explain that in the API documentation.

---

<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:** [March 7, 2021, 2:23am UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/97 "2021-03-07T02:23:55Z")

</div>

> [@celebytes20212iy4](#):
>
> I added some more blocks and values. Is this correct?

I would ask you… does it work?

Again, I’d recommend **not** using the “status” block at all. You’re creating a set of blocks that will never run because of how you are setting up your if/else statements.

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 8, 2021, 8:44pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/98 "2021-03-08T20:44:31Z")

</div>

Hi! Sorry for responding so late I was working on the project. I think that these blocks should work but when I test it no text shows up? Is there an error with the code?

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

---

<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:** [March 8, 2021, 9:05pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/99 "2021-03-08T21:05:37Z")

</div>

You’re getting really side-tracked. I think you might need someone to walk you through this over Zoom/etc.

The green response block contains the wall of text that you get when you put the API url into a browser. So to then check to see if “response” = a number between 0 and 2 doesn’t make any sense. It would be like saying “does a dictionary equal four?”

You should only use the green response block at the very beginning to get the object from the API. After that, you should only be using “get property of object” blocks to get individual pieces of data from the JSON.

If you’re a student, do you have a teacher who is able to help you with this?

---

<div class="post-metadata">

**Author:** ![celebytes20212iy4](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@celebytes20212iy4](https://community.thunkable.com/u/celebytes20212iy4)\
**Post date:** [March 8, 2021, 9:21pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/100 "2021-03-08T21:21:16Z")

</div>

No I do not have a teacher to help me with this.  
So what would I have to check in the “if” block?

---

<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:** [March 8, 2021, 9:45pm UTC](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955/101 "2021-03-08T21:45:31Z")

</div>

This isn’t something I can really explain over forum posts. I’ve tried several times above. There are concepts related to programming that you may have to learn such as how if/else statements work and how variables (such as the green blocks in Thunkable) store information.

I can suggest re-watching my tutorial video and probably watching some other videos related to programming with Thunkable.

[Previous page](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955.md?page=4)

[Next page](https://community.thunkable.com/t/how-to-create-nutrition-app-with-ocr-scanner/1113955.md?page=6)
