# Help with curl notation for Web API call

**URL:** <https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758>\
**Category:** Questions about Thunkable X\
**Tags:** webapi, curl\
**Created:** [November 17, 2020, 6:51pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758 "2020-11-17T18:51:24Z")\
**Posts on this page:** 17\
**Page:** 1

<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:** [November 17, 2020, 6:51pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/1 "2020-11-17T18:51:24Z")

</div>

I’m trying to wrap my ahead around **curl** notation… I know this is not exactly a Thunkable question but it’s about to become one when I create the blocks for this…

I’m trying to get info from Microsoft’s AI Earth Web API. The [documentation](https://aiforearth.portal.azure-api.net/docs/services/species-classification-v2/operations/predict?) shows this Request URL and sample _curl_ command but it doesn’t include the image url that I need to send along with the command. So I’m trying to add that in.

> Request URL  
> [https://aiforearth.azure-api.net/species-classification/v2.0/predict[?topK][&predictMode]](https://aiforearth.azure-api.net/species-classification/v2.0/predict%5B?topK%5D%5B&predictMode%5D)
> 
> ```auto
> @ECHO OFF
> 
> curl -v -X POST "https://aiforearth.azure-api.net/species-classification/v2.0/predict?topK={integer}&predictMode={string}"
> -H "Ocp-Apim-Subscription-Key: {subscription key}"
> 
> --data-ascii "{body}" 
> 
> ```

This is what I have so far. Depending on how I tweak the command, I can get various responses that indicate a failed send or a misformatted media format. I’ve tried about 20 different combinations so I’m hoping someone more familiar with _curl_ can assist me. Note that the Subscription Key shown here is not a valid one; I do have a valid key.

curl -v -X POST -H “Ocp-Apim-Subscription-Key: lOEflwP0ouh9tv6zmKr” -H “Content-Type: application/json” -d “{url: [http://2.bp.blogspot.com/-\_fWU03Q9sDM/Ubwtc\_ipPII/AAAAAAAAAfk/GnUQG6t5rto/s1600/Barn-Owl-Facts.JPG](http://2.bp.blogspot.com/-_fWU03Q9sDM/Ubwtc_ipPII/AAAAAAAAAfk/GnUQG6t5rto/s1600/Barn-Owl-Facts.JPG)}” "[https://aiforearth.azure-api.net/species-recognition/v2.0/predict?topK=1&predictMode=classifyOnly”](https://aiforearth.azure-api.net/species-recognition/v2.0/predict?topK=1&predictMode=classifyOnly%E2%80%9D)

And here are the parts of that same command split apart for easier viewing:

curl -v -X POST

-H “Ocp-Apim-Subscription-Key: lOEflwP0ouh9tv6zmKr”

-H “Content-Type: application/json”

-d “{url: [http://2.bp.blogspot.com/-](http://2.bp.blogspot.com/-)

\_fWU03Q9sDM/Ubwtc\_ipPII/AAAAAAAAAfk/GnUQG6t5rto/s1600/Barn-Owl-Facts.JPG}”

"[https://aiforearth.azure-api.net/species-recognition/v2.0/predict?topK=1&predictMode=classifyOnly”](https://aiforearth.azure-api.net/species-recognition/v2.0/predict?topK=1&predictMode=classifyOnly%E2%80%9D)

---

<div class="post-metadata">

**Author:** ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)\
**Post date:** [November 17, 2020, 7:08pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/2 "2020-11-17T19:08:11Z")

</div>

Have you tried blocking it out with the WEB\_API? I know a few tricks for translating CURL into blocks, but I don’t know how to work directly with CURL

---

<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:** [November 17, 2020, 7:19pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/3 "2020-11-17T19:19:23Z")

</div>

@drted Yeah, I started with blocks, actually. And then when it became tedious to keep changing them, I switched to curl. Also, the Web\_API returns only a status value from their servers. Nothing’s ever in the green error block. Whereas when I run it in Terminal using curl, I at least get some error messages back from their server.

I think I just have some syntax wrong. Probably a header or parameter name. I’m checking with the director of the program so hopefully he will set me straight.

I’m honestly not always sure what goes in url vs. header vs. query parameter blocks. I end up doing a lot of trial and error until I hit upon the right combination.

---

<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:** [November 17, 2020, 7:35pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/4 "2020-11-17T19:35:07Z")

</div>

@drted

 ![Screen Shot 2020-11-17 at 11.34.43 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/7/678ccfe73151ae561722fa58235e225518702241.png)

![Screen Shot 2020-11-17 at 11.36.34 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/a/8a438ce038625620ecd53ba7e081f7a8890bf236.png)

---

<div class="post-metadata">

**Author:** ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)\
**Post date:** [November 17, 2020, 8:05pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/5 "2020-11-17T20:05:23Z")

</div>

@tatiang,

A few thoughts:

I’ve found APIs put info in the darnedest places, so I always display error, status, and response when debugging:

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

It looks like you need 2 header properties:

> curl -v -X POST -H “ **Ocp-Apim-Subscription-Key:** lOEflwP0ouh9tv6zmKr” -H “ **Content-Type:** application/json”

Don’t be like me and try to put them in a list. It should be one object with 2 properties.  
I think the url should be in the body, not the header ( but I might be wrong).

When using the body, you cannot use Thunkable object blocks directly, you need to GENERATE JSON FROM OBJECT (because Thunkable)

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/5/4511dffed1a7d8a71f156626781e2b4ba35e4ae6.jpeg)

I’ve struggled to get the parmeter block to work consistently. Here is an example of it working

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

Unfortunately, sometimes I resort to JOINing a long URL block ☹. Honestly, I usually start here, and once I get it to work, I move them to blocks, because Thunkable.

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

Happy Thunking!

---

<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:** [November 17, 2020, 8:23pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/6 "2020-11-17T20:23:20Z")

</div>

Thanks, @drted. I take the same approach. I actually was displaying the error, status and response above… I just assumed that a response wouldn’t be helpful if there was an error or the status was ≠ 200. But I’ll try your way.

**Edit:** you’re right! It was returning a response along with a status ≠ 200.

I like this little trick:

 ![Screen Shot 2020-11-17 at 12.25.37 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/e/1e7961e79fe6e91310f94362a5e24a5576bf3822.png)

And yeah, I too start with a long url that contains everything and then break it apart with join blocks once it’s working. I just couldn’t get to that point.

---

<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:** [November 17, 2020, 8:33pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/7 "2020-11-17T20:33:34Z")

</div>

Here’s what I have so far. I think I might be able to parse the right fields from this document that I just found: [https://aiforearth.portal.azure-api.net/docs/services/species-classification-v2/export?DocumentFormat=OpenApiJson](https://aiforearth.portal.azure-api.net/docs/services/species-classification-v2/export?DocumentFormat=OpenApiJson). Especially after running it through this for better formatting: [https://jsonformatter-online.com](https://jsonformatter-online.com).

 ![Screen Shot 2020-11-17 at 12.32.22 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/5/b5065ab7db11c467a0900a2e21ae724efcbb791d.png)

 ![Screen Shot 2020-11-17 at 12.33.14 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/3/d308d811c34d0c36a830b10fe672058228babbb3.png)

---

<div class="post-metadata">

**Author:** ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)\
**Post date:** [November 17, 2020, 9:34pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/8 "2020-11-17T21:34:23Z")

</div>

These blocks

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/8/88cedbd9f2779ec8ffd095c2ec1a09acdd9bc1a7.png)  
Give me this result  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/a/aafd0e4ae599e1f00fab66a64662231c1dbb14a6.png)

Are you able to connect without the body?  
Do you have the same URL as I do (yours has elipses)?

---

<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:** [November 17, 2020, 9:42pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/9 "2020-11-17T21:42:39Z")

</div>

Yep, same url as you: [https://aiforearth.azure-api.net/species-classification/v2.0/predict](https://aiforearth.azure-api.net/species-classification/v2.0/predict)

I’m also trying Content-Type: application/octet-stream

---

<div class="post-metadata">

**Author:** ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)\
**Post date:** [November 17, 2020, 9:58pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/10 "2020-11-17T21:58:19Z")

</div>

Yeah, that documentation assumes more than I know. Sorry, I’m stumped ☹

---

<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:** [November 17, 2020, 10:01pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/11 "2020-11-17T22:01:07Z")

</div>

That’s okay, I appreciate you trying!

---

<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:** [November 21, 2020, 4:23am UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/13 "2020-11-21T04:23:02Z")

</div>

I think I understood most of this. But why are you using if status is not equal to 200? What exactly does ‘200’ signify?

---

<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:** [November 21, 2020, 4:28am UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/14 "2020-11-21T04:28:08Z")

</div>

Thanks @drted for trying this out!

---

<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:** [November 21, 2020, 4:56am UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/15 "2020-11-21T04:56:17Z")

</div>

> [@codeswept](#):
>
> I think I understood most of this. But why are you using if status is not equal to 200? What exactly does ‘200’ signify?

JSON responses return a “status” value. If it’s 200, it indicates that the JSON call/request went through correctly. You can see a description of that here (as well as many other sites): [HTTP Status Codes](https://restfulapi.net/http-status-codes/#:~:text=200%20(OK),should%20include%20a%20response%20body).

---

<div class="post-metadata">

**Author:** ![anushka](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@anushka](https://community.thunkable.com/u/anushka)\
**Post date:** [November 21, 2020, 5:15am UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/16 "2020-11-21T05:15:14Z")

</div>

Hm… ok.

---

<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:** [November 21, 2020, 7:06am UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/17 "2020-11-21T07:06:36Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 12:21pm UTC](https://community.thunkable.com/t/help-with-curl-notation-for-web-api-call/980758/18 "2024-11-08T12:21:33Z")

</div>


