Dream factory call REST API and character parameter - rest

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*'

Related

Curl, How to send list of strings using GET request?

I want to send ['1', '2', '3'] as a GET request.
I thought GET request are used when you are retrieving data opposed to POST (when you are modifying/creating data)
Failing to google how to send list of strings with GET does make me wonder, if it's better to use POST here?
Once you intend to perform a GET request, you could send data in the query string using one of the following approaches:
curl -G http://example.org -d "query=1,2,3"
curl -G http://example.org -d "query=1&query=2&query=3"
Let me highlight that payloads in GET requests are not recommended. Quoting the RFC 7231:
A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.
Also bear in mind that GET requests shouldn't be used to modify resources: they are intended to be used for information retrieval only, without side effects. Having said that, GET is both safe and idempotent. You can see more details on these concepts in this answer.
If the data must be sent in the payload (and you intend to modify the resource) then stick to POST. Assuming your payload is a JSON document, you would have something like:
curl -X POST http://example.org \
-H "Content-Type: application/json" \
-d '["1", "2", "3"]'
If you want to send it in the body with curl you can call your service like this:
curl -X GET --data "['1', '2', '3']" "https://example.com/test.php"
For example in PHP you can read it from the read-only stream php://input
<?php
$get_body = file_get_contents('php://input');
A better way would be to assign the array to a parameter e.g. x:
curl -X GET "https://example.com/test.php?x[]=1&x[]=2&x[]=3"
In PHP you'll receive these values as an array in $_GET['x']:
<?php
print_r($_GET['x']);
Output:
Array
(
[0] => 1
[1] => 2
[2] => 3
)

How to run h2o AutoML by using rest api?

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.

How to use Matlab webread with 2 http headers

I need to do this GET call with matlab:
curl -X GET \
-H "X-Parse-Application-Id: my_AppKEY" \
-H "X-Parse-REST-API-Key: my_APIKEY" \
https://api.parse.com/1/classes/GameScore
(this is a basic request to parse.com)
In matlab 2014b I have the function webread which becomes a weboptions struct.
I think the correct way of setting a header for the request is like this:
myHeaders1 = weboptions('KeyName', 'X-Parse-Application-Id', 'KeyValue' , 'my_KEY')
The thing is... I can only set 1 header using this syntax. How can I set 2 or more headers to be used in webread?
You can either call curl from within Matlab if you load right library files or instead you can use urlread2

Low confidences with DBpedia Spotlight

I am a little bit confused why I get such low confidences with the REST API of Spotlight.
I run the following code/call:
curl http://spotlight.dbpedia.org/rest/annotate \
--data-urlencode "text=Hallo, i am looking for a new Microsoft or Apple tablet." \
--data "confidence=0.2" \
--data "support=20"
then I just get similarityScores between 0.130 and 0.135.
When I try this text in the demo (http://dbpedia-spotlight.github.io/demo/) then I can get the results until to a confidence of 0.60.
What cause my low confidence values? How can I obtain correct values?
p.s. Is there anywhere a more comprehensive documentation?
First similarityScores does not correspond to the values of Confidence.
But more importantly http://spotlight.dbpedia.org/rest/annotate is not the endpoint being used by the demo.
The endpoint being used by the demo is: http://spotlight.sztaki.hu:2222/rest

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.