cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
smehro
Helper I
Helper I

Custom Connector #Clarifai_API

Hi,

 

I am unable to utilize Clarifai_API for in-built food detection model.

I followed the tutorial mentioned at https://docs.clarifai.com/ & https://www.clarifai.com/models/ai-food-recognition but the operations that I need to perform are not getting through.

Basically, I require my canvas app to pass an image to the API and in return the API provides ingredients list.

I used API key for security:

smehro_0-1629121751852.png

General definition as this

smehro_1-1629121791074.png

Request as

smehro_2-1629121820680.png

Header as (from https://docs.clarifai.com/clarifai-basics/authentication/authorize)

 

curl -X POST \
  -H 'Authorization: Key YOUR_API_KEY' \
  -H "Content-Type: application/json" \
  -d '

 

 The results shows custom connector is created but I simply can't test it.

CC: @v-xiaochen-msft , @cchannon 

Sid

1 ACCEPTED SOLUTION

Accepted Solutions
v-xiaochen-msft
Community Support
Community Support

Hi @smehro ,

 

I agreed with @cchannon .

I did a sample for you.

vxiaochenmsft_0-1629250817486.png

vxiaochenmsft_1-1629250840313.png

vxiaochenmsft_2-1629250852673.png

 

Add a post request .

vxiaochenmsft_3-1629250924853.png

URL:https://api.clarifai.com/v2/models/bd367be194cf45149e75f01d59f77ba7/versions/dfebc169854e429086aceb8...

 

Header:Authorization Key {your key}

 

Body:

{
    "inputs": [
        {
            "data": {
                "image": {
                    "url": "https://samples.clarifai.com/metro-north.jpg",
                    "allow_duplicate_url": true
                }
            }
        }
    ]
}

 

Add a policy

vxiaochenmsft_4-1629251022411.png

@headers('Access-Token')

 

Save and test it.

vxiaochenmsft_5-1629251094186.png

vxiaochenmsft_6-1629251131204.png

 

In addition, I did not add response in my example, please don't forget to add it.

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

 

 

View solution in original post

6 REPLIES 6
cchannon
Super User
Super User

There's a few things here.

 

1. Your url is wrong. I looked at the clarifyai documentation for a few minutes and quickly found this page which details how to call their predict endpoint for images. What you'll see there is that the url for the requests follows the format: 

https://api.clarifai.com/v2/models/{THE_MODEL_ID}/outputs

 2. You haven't defined any body or qs params as far as I can tell. At a minimum, you need to build a JSON body to actually send your image to the api. From the quick glance I took at the documentation, it looks like that body is formed something like this:

{
   "data": {
      "image": {
         "base64": "'"$(base64 /path/to/image.jpg)"'"
      }
   }
}

 3. Custom Connectors don't know how to read curl commands. You need to build the header in JSON for the swagger to understand it.

v-xiaochen-msft
Community Support
Community Support

Hi @smehro ,

 

I agreed with @cchannon .

I did a sample for you.

vxiaochenmsft_0-1629250817486.png

vxiaochenmsft_1-1629250840313.png

vxiaochenmsft_2-1629250852673.png

 

Add a post request .

vxiaochenmsft_3-1629250924853.png

URL:https://api.clarifai.com/v2/models/bd367be194cf45149e75f01d59f77ba7/versions/dfebc169854e429086aceb8...

 

Header:Authorization Key {your key}

 

Body:

{
    "inputs": [
        {
            "data": {
                "image": {
                    "url": "https://samples.clarifai.com/metro-north.jpg",
                    "allow_duplicate_url": true
                }
            }
        }
    ]
}

 

Add a policy

vxiaochenmsft_4-1629251022411.png

@headers('Access-Token')

 

Save and test it.

vxiaochenmsft_5-1629251094186.png

vxiaochenmsft_6-1629251131204.png

 

In addition, I did not add response in my example, please don't forget to add it.

 

Best Regards,
Wearsky
If my post helps, then please consider Accept it as the solution to help others. Thanks.

 

 

 

View solution in original post

Thanks Wearsky!

I performed the steps you mentioned. However, I am getting an error for header: Authorization.

The error is: 'Authorization' header is not allowed. Use 'API Key' authentication type in the Security tab to set this header.

smehro_0-1629275389418.png

smehro_1-1629277137760.png

I have set authentication type to 'NO Authentication' in the security tab as your screenshot.

v-xiaochen-msft
Community Support
Community Support

Hi @smehro ,

 

Rename this param. (Access-Token)

vxiaochenmsft_1-1629277339991.png

 

vxiaochenmsft_0-1629277281613.png

 

Best Regard,

Wearsky

Hi Wearsky,

It works! Thanks. 😊

One last thing: I tried to use a similar custom connector with Onselect of a button as:

 

Collect(spoonresponses,Spoonacular.acularimage({apiKey:"xxxxxxxx",imageUrl:"https://cdn.pixabay.com/photo/2019/10/12/15/39/falafel-4544137_960_720.jpg",'Content-Type':"application/json"}));

Set(spoondataanswer,spoondata.Run(JSON(spoonresponses,JSONFormat.IndentFour))

 

 I get error: "Invalid type. Expected Object but got Array." in Power Flow.

smehro_0-1629278717213.pngsmehro_1-1629278743348.png

Basically, this seems to be an issue with the collector as when there are more than 1 item it sends an array instead of object. The issue is now how to parse a JSON array!

I was able to rectify this by changing schema to an array.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,469)