watson visual recognition error 400: cannot execute learning task: no classifier name given - ibm-cloud

I was about to create a new classifier and train the visual recognition with pictures, but I got this error code which is stated in title when I curl following command
curl -u "0xxxxxxxxxxx":"vxxxxxxxxxxxxxx" \
-X POST \
-F "positive_examples=#bottle-positive.zip" \
-F "negative_examples=#bottle-negative.zip" \
-F "name=plasticbottle" \
-k "https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classifiers?version=2015-12-02"

To set the classifiers you want to use you have to send a JSON containing something like:
{"classifier_ids": ["ClassifierName"]}
So your curl should be something like:
curl -u "username":"pwd" \
-X POST \
-F "images_file=#imagefilename.jpg" \
-F "classifier_ids={\"classifier_ids\":[\"ClassifierName\"]}"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"

I'm not sure what was the problem using V2 api, but now, using V3 API your CURL should look like this example
curl -X POST
-F "apple_positive_examples=#apples1.zip"
-F "banana_positive_examples=#yellow.zip"
-F "orange_positive_example=#pos_ex.zip"
-F "negative_examples=#vegetables.zip"
-F "name=fruit"
"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key={api-key}&version=2016-05-20"
So your CURL for bottle should be like
curl -X POST
-F "bottle_positive_examples=#bottle-positive.zip"
-F "negative_examples=#bottle-negative.zip"
-F "name=plasticbottle"
"https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classifiers?api_key={api-key}&version=2016-05-20"
Note that you now should use an api_key to authenticate and no longer a user/pass
This is documented in the v3 doc:
https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/#create_a_classifier

Related

How to send HTTP request multipart/form-data Content-Type on Apex Salesforce

I need to recreate this curl post using Apex and I can't find a way to do it.
Seems like Salesforce doesn't support this kind of Content-Type.
curl:
curl -i -X POST \
-H "Content-Type:multipart/form-data" \
-F "message=Images Test" \
-F "login=LOGIN" \
-F "password=PASSWORD" \
-F "to=9999999999" \
-F "image=#\"./20190914_132720.jpg\";type=image/jpeg;filename=\"20190914_132720.jpg\"
Anyone has an example of this on Apex?
Thank you

Curl error: option-less arguments found

I'm trying to import this example into postman
curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
-F from='Excited User <mailgun#YOUR_DOMAIN_NAME>' \
-F to=YOU#YOUR_DOMAIN_NAME \
-F to=bar#example.com \
-F subject='Hello' \
-F text='Testing some Mailgun awesomness!'
Please help me understand the -s, --user, -F, what is that? And then when I try to import, I get this error: option-less arguments found. How can I fix this?
If you're trying to execute curl commands in Postman, select Import, then Paste Raw Text and then copy the command, but first remove all backslashes.

CQ5.5 Updating an existing package through CURL

I am using a series of CURL request to create my package.
What I am doing currently: I created a new package, added filters to it and then built the package.
Create package:
curl -f -N -u ${USER}:${PASS} -d "packageName=${PACKAGE}&groupName=${GROUP}" "${CMS_HOST}/crx/packmgr/service/exec.json?cmd=create"
Apply Filters:
curl -f -N -u ${USER}:${PASS} -F "path=/etc/packages/${GROUP}/${PACKAGE}.zip" -F "packageName=${PACKAGE}" -F "groupName=${GROUP}" -F "version=" -F "description=" -F "thumbnail=" -F "filter=${FILTER}" -F "_charset_=UTF-8" "${CMS_HOST}/crx/packmgr/update.jsp"
Build Package:
curl -f -N -u ${USER}:${PASS} -d "cmd=build" "${CMS_HOST}/crx/packmgr/service/script.html/etc/packages/${GROUP}/$PACKAGE.zip"
What I want to do: Add more filters to this package and build it again.
I am wondering if there is a way to update an existing package. I have been searching around to see how we can do this but have failed. Can someone please help me?
Thanks.
Update: Added the CURL commands I am using.
Here you go with an example where i have a package with two filters already
Going to add another filter
CURL for Create a Filter Node
curl --data jcr:primaryType=nt:unstructured --user admin:admin http://localhost:4502/etc/packages/my_packages/testcurl.zip/jcr:content/vlt:definition/filter/f2
Add the Filter properties
curl -u admin:admin -Froot="/content/geometrixx-outdoors/en/toolbar" http://localhost:4502/etc/packages/my_packages/testcurl.zip/jcr:content/vlt:definition/filter/f2.rw.html
IF required add additional properties (i.e. "mode" & "rules") for the Default package behaviour
curl -u admin:admin -Fmode="replace" http://localhost:4502/etc/packages/my_packages/testcurl.zip/jcr:content/vlt:definition/filter/f2.rw.html
curl -u admin:admin -Frules#TypeHint="String[]" -Frules=" " -Frules=" "http://localhost:4502/etc/packages/my_packages/testcurl.zip/jcr:content/vlt:definition/filter/f2.rw.html
Finally build your package to affect additional filter to add to your existing package
curl -u admin:admin -X POST http://localhost:4502/crx/packmgr/service/.json/etc/packages/my_packages/testcurl.zip?cmd=build
All the packages are stored under /etc/packages/my_packages path which can be modified by standard curl commands for node management. All packages have filters as sub-nodes.
All package manager commands are available via /crx/packmgr/service.jsp?cmd=help
For example, in order to build a package use /crx/packmgr/service.jsp?cmd=build

Post photos to an album using a batch request and curl

I'm trying to post a number of photos to an already created album using cURL with the following command:
curl -F 'access_token=<>' \
-F 'batch=[ \
{"method":"POST","relative_url":"/album_id/photos","url":"<photo_url>"}, \
{"method":"POST","relative_url":"/album_id/photos","url":"<photo_url>"}]' \
https://graph.facebook.com
The error I'm getting is (#324) Requires upload file. Is it even possible to post photos in a batch request to an album and if so what is the correct way to do it with cURL? Thanks!
Edit: the correct command thanks to CBroe is:
curl -F 'access_token=<>' \
-F 'batch=[ \
{"method":"POST","relative_url":"/album_id/photos","body":"url=<photo_url>"}, \
{"method":"POST","relative_url":"/album_id/photos","body":"url=<photo_url>"}]' \
https://graph.facebook.com

Visual Recognition error 400: Cannot execute learning task no classifier name given

I am using Visual Recognition curl command to add a classification to an image:
curl -u "user":"password" \
-X POST \
-F "images_file=#image0.jpg" \
-F "classifier_ids=classifierlist.json" \
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classifiers?version=2015-12-02"
json file:
{
"classifiers": [
{
"name": "tomato",
"classifier_id": "tomato_1",
"created": "2016-03-23T17:43:11+00:00",
"owner": "xyz"
}
]
}
(Also tried without the classifiers array. Got the same error)
and getting an error:
{"code":400,"error":"Cannot execute learning task : no classifier name given"}
Is something wrong with the json?
To specify the classifiers you want to use you need to send a JSON object similar to:
{"classifier_ids": ["Black"]}
An example using Black as classifier id in CURL:
curl -u "user":"password" \
-X POST \
-F "images_file=#image0.jpg" \
-F "classifier_ids={\"classifier_ids\":[\"Black\"]}"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"
If you want to list the classifier ids in a JSON file then:
curl -u "user":"password" \
-X POST \
-F "images_file=#image0.jpg" \
-F "classifier_ids=#classifier_ids.json"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"
Where classifier_ids.json has:
{
"classifier_ids": ["Black"]
}
You can test the Visual Recognition API in the API Explorer.
Learn more about the service in the documentation.
The model schema you are referencing, and what is listed in the API reference, is the format of the response json. It is an example of how the API will return your results.
The format of the json that you use to specify classifiers should be a simple json object, as German suggests. In a file, it would be:
{
"classifier_ids": ["tomato_1"]
}
You also need to use < instead of # for the service to read the contents of the json file correctly. (And you might need to quote the < character on a command line since it has special meaning (redirect input).) So your curl would be:
curl -u "user":"password" \
-X POST \
-F "images_file=#image0.jpg" \
-F "classifier_ids=<classifier_ids.json"
"https://gateway.watsonplatform.net/visual-recognition-beta/api/v2/classify?version=2015-12-02"