How to run h2o AutoML by using rest api? - rest

I want run AutoML in h2o by using rest api? I know the url is /99/AutoMLBuilder. But I have no idea that how can I send the parameters. There is no sample code on the official web site. I can access model import/export by using curl because the parameters are flat. But it seems that maybe the parameters of AutoML are nested, and I cannot find any sample code or answers about the format of the parameters.

The parameters are sent in JSON format through a POST command. For example, assuming a training frame named airlines has already been loaded, you can train an AutoML model through curl with:
curl -X POST http://localhost:54321/99/AutoMLBuilder -H "Content-Type: application/json" -d '{"input_spec": {"training_frame":"airlines", "response_column":"IsDepDelayed"}, "build_control": {"project_name":"aml_curl_test", "stopping_criteria":{"max_models":3} } }'
You can find the full REST API reference here: http://docs.h2o.ai/h2o/latest-stable/h2o-docs/rest-api-reference.html, which will tell you the JSON object names each parameter belongs to.

Related

Calling Orthanc's REST Api from Lua returns a "URI Badly Formatted" error

I am trying to anonymize images before sending them to another Orthanc server.
According to the documentation on anonymization, Orthanc can anonymize images through the REST api:
http://book.orthanc-server.com/users/anonymization.html
Orthanc allows to anonymize a single DICOM instance and to download
the resulting anonymized DICOM file. Example:
$ curl http://localhost:8042/instances/6e67da51-d119d6ae-c5667437-87b9a8a5-0f07c49f/anonymize -X POST -d '{}' > Anonymized.dcm
According to the documentation page on Lua scripts, Lua scripts can take advantage of the REST API:
Lua scripts have full access to the REST API of Orthanc
The page goes on to describe how to use call the REST API from Lua:
functions:
RestApiGet(uri, builtin)
RestApiPost(uri, body, builtin)
RestApiPut(uri, body, builtin)
RestApiDelete(uri, builtin)
The uri arguments specifies the URI against which to make the request, and body is a string containing the body of POST/PUT request.
This means that I should be able to call the REST API from Lua by combining the functions above.
However when calling the RestApiPost as described in the documentation.
instances = RestApiGet(http://localhost:8042/instances, true)
I get the following error
E0313 17:40:40.851840 LuaScripting.cpp:358] Lua: Badly formatted URI
E0313 17:40:40.851884 LuaScripting.cpp:361] Lua: Error in RestApiPost() for URI: http://localhost:8042/instances/b38a8ef0-909f8ac0-7eca907a-75c98187-8e5339f4/anonymize
It's worth noting that I can call this endpoint correctly from curl and from my browser. Removing the 'http://' section didn't solve the issue.
The RestApiGet function and its family expect the developer to format the uri parameter without 'http://localhost:8042' as follows:
'/instances'
These functions only work for using the REST API provided by the Orthanc the Lua script is running on, so it already knows that you will use the localhost and it will use the correct http scheme and 8042 port automatically.
As described in http://book.orthanc-server.com/users/lua.html#general-purpose-functions, the function HttpGet(url, headers) and its family are the general form of this function and allow the developer to query any http endpoint.

Dream factory call REST API and character parameter

Currently, I have a problem with Dream Factory REST API call, when a space is present into the API URL call.
I have a get request with a sort parameter that must to be send for SOLR server. This space I don’t know how it is converted, but it seems to arrive into not appropriate mananer.
curl -X GET
‘http://localhosts:81/api/v2/test/list/test?rows=10&sort=random_test%20desc’
-H ‘X-DreamFactory-Api-Key: e115f92d18ba58e9a29389’
-H ‘X-DreamFactory-Session-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1’
SOLR need to have this sort parameter and the direction of the sort. So we provide the column to sort, space and the direction. When I execute this curl using Dream Factory api, then the space or the %20 character seems to be converted into other thing.
Is there someone knowing, if this is a Dream factory problem, or whether it is possible to make the call in another manner?
Finaly the solution that I found is to change the curl call in order to make POST request and to put the parameters with spaces into the -d parameter.
Here is the call working for our case :
curl -X POST \
'http://localhost:81/api/v2/test/list/test?rows=10' \
-H 'X-DreamFactory-Api-Key: e115f92d18ba58e9a2' \
-H 'X-DreamFactory-Session-Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJz' \
-d 'sort=random_test+DESC&fq=NAME:*ov*+OR+NAME:*a*'

SoftLayer Rest API attachDiskImage call throwing error

I am trying with the below one it always throws "You must provide a valid portable storage volume id.". I have replaced my virtualGuestId,imageId,user name and apikey in below curl.
curl "https://[username]:[apiKey]#api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/[virtualGuestId]/attachDiskImage.json?imageId=[imageId]"
Please let me know the correct API to use to load an disk image and how to fetch the details of disk image.
I recomend you to take a look at these links:
https://sldn.softlayer.com/blog/bpotter/more-softlayer-rest-api-examples
https://sldn.softlayer.com/article/REST
Well the method attachDiskImage has as parameters the "imageId" of the portable storage as you can see in documentation:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/attachDiskImage
The parameters must be sent using the POST method and you need to send those parameters in a payload with a JSON format, so your request should be changed to this one:
curl -X POST -d '{"parameters":[$IMAGEID]}' https://$SLUSERNAME:$SLAPIKEY#api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/$VIRTUALGUESTID/attachDiskImage.json
Note: replace $IMAGEID, $SLUSERNAME, $SLAPIKEY and $VIRTUALGUESTID
Regards

Matlab: using webwrite to send image through a simple REST API

I was trying to do image classification through a web at service at and
I had no problem to use curl to retrieve token:
curl -i -X POST -H "Authorization:MY Key" -F "image_request[image]=#/path/to/myimage" -F "image_request[locale]=en-US" https://api.cloudsightapi.com/image_requests
However, it is not successful when I tried webwrite, it returned "HTTP 400" error.
option=weboptions('KeyName','Authorization','KeyValue','mykey')
fid = fopen('/path/to/myimage');
img = fread(fid,Inf,'*uint8');
fclose(fid);
response=webwrite('https://api.cloudsightapi.com/image_requests',...
'image_request[image]',img,...
'image_request[locale]','en-US',option);
I guess it because the function webwrite in this format doesn't support "multipart/form-data" and I need change the media type. Then I tried to send data as an JSON object
option=weboptions('KeyName','Authorization','KeyValue','mykey','MediaType','application/json')
data=struct('image_request[image]',im,'image_request[locale]','en-US');
response=webwrite('https://api.cloudsightapi.com/image_requests',data,option)
But the field name in Matlab struct does not allow "[".
Any suggestion?

Unable to accept songs submitted to moderated group via SoundCloud API

I'm getting 404 when hitting url like this, (offc. with variables changed to proper values):
PUT https://api.soundcloud.com/groups/<group_id>/pending_tracks/<track_id>
Calling DELETE on that same URL works as expected, it rejects submission from group.
Requesting simple GET .../pending_tracks (no track-id at the end) works fine for me.
The tools I have used so far to test this are:
official PHP library (by mptre),
manually constructed cURL request,
cURL binary on windows
I couldn't find any info in SoundCloud API docs (or on the internet) how this API method should or could be used. Any chance someone could help me with how it is supposed to be accessed properly, these are the questions:
what is the correct url
if there should be any, what is expected as the query data
if there a query body and what is the format.
More details:
Calling PUT /groups/44/pending_tracks/99119291 returns 404, so I've figured
out, the track ID must be supplied some other way.
By digging trough the PHP wrapper and gathering pieces of info scattered
around the internet, I've found out that some PUT requests are complemented
with CURLOPT_POSTFIELDS and other have XML in their body. So far I went with
postfields approach.
My curl binary config looks like this:
--url https://api.soundcloud.com/groups/44/pending_tracks
--cacert cacert.pem
--user-agent PHP-SoundCloud
--header "Accept: application/json"
--header "Authorization: OAuth XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
--request PUT
--data <!--read on please-->
The data section was tested with following strings, each time supplying as
a value track-id like this track[id]=99119291:
track
track[]
track[id]
track-id
track_id
trackid
approve
approved
approve[]
approve[tracks][]
approved[tracks][]
tracks[approve][]
tracks[approved][]
approve[tracks][][id]
approved[tracks][][id]
tracks[approve][][id]
tracks[approved][][id]
tracks[]
tracks[][id]
tracks[][track][id]
tracks[][track][][id]
group[][id]
group[approve][]
group[approve][id]
group[approve][][id]
group[approved][]
group[approved][id]
group[approved][][id]
group[track][approve]
group[track][approve][]
group[track][approved][]
group[track][approve][id]
group[track][approve][][id]
group[track][approved][][id]
group[track][id]
group[tracks][id]
group[track][][id]
group[tracks][][id]
group[tracks][]
groups[][id]
groups[approve][id]
groups[approve][][id]
groups[approved][id]
groups[approved][][id]
groups[track][approve]
groups[track][approve][]
groups[track][approved][]
groups[track][approve][id]
groups[track][approve][][id]
groups[track][approved][][id]
groups[track][id]
groups[tracks][id]
groups[track][][id]
groups[tracks][][id]
Needless to say, none of those worked, each time result was the same as if I was accessing API endpoint with a simple GET request.
I'm really tired of blindly poking the SoundCloud API.
I'm sorry for you pain with the API, I fully agree it deserves a lot more and better documentation.
Anyway, while it's unclear to me why it got implemented like this, you should be able to approve tracks by sending a PUT request to api.soundcloud.com/groups/:group_id/tracks/:track_id. I hope that helps.