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 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.
@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.
@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.
I’ve found APIs put info in the darnedest places, so I always display error, status, and response when debugging:
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)
I’ve struggled to get the parmeter block to work consistently. Here is an example of it working
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.
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.
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.