How to query predictionio for a particular app - machine-learning

I have created multiple apps in predictionio.
While inserting events in predictionio, there a parameter accessKey (associated to app) which is passed.
Whereas for queries.json, couldn't find the accessKey parameter.
Sample below:
curl -H "Content-Type: application/json" \
-d '{ "items": ["i1", "i3"], "num": 10, "categories" : ["c4", "c3"], "blackList": ["i21", "i26", "i40"] }' \
http://localhost:8000/queries.json
{"itemScores":[{"item":"i39","score":1.0773502691896257},{"item":"i44","score":1.0773502691896257},{"item":"i14","score":1.0773502691896257},{"item":"i45","score":0.7886751345948129},{"item":"i47","score":0.7618016810571367},{"item":"i6","score":0.7618016810571367},{"item":"i28","score":0.7618016810571367},{"item":"i9","score":0.7618016810571367},{"item":"i29","score":0.6220084679281463},{"item":"i30","score":0.5386751345948129}]}
Now, how to query data for a particular app?

Related

Issues search error: Unexpected character (''' (code <N>)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

I am trying to get this same type of query.
curl -u admin:admin -X POST localhost:50813/rest/api/2/search -H "Content-Type: application/json" -d '{"jql":"updated > -1d","fields":[""]}' -s | jq > jql-output.txt
But hitting error.
I ref this query from
https://confluence.atlassian.com/jirakb/how-to-programmatically-update-issues-from-a-jql-using-rest-api-in-jira-1031284474.html
Error which I am getting for now is to debug further.
curl -u admin:admin -X POST localhost:50813/rest/api/2/search -H "Content-Type: application/json" -d '{"jql":"updated > -1d","fields":[""]}'
Error:
{"errorMessages":["Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream#c502a0b; line: 1, column: 2]"]}
Any idea? Been trying various options. No clear solution
Yes, it seems this is a documentation error. You can basically remove the fields from request (and it returns all fields as default) or you can set it from one of the following as stated in another Jira documentation:
By default, only navigable (*navigable) fields are returned in this
search resource. Note: the default is different in the get-issue
resource -- the default there all fields (*all).
*all - include all fields
*navigable - include just navigable fields
summary,comment - include just the summary and comments
-description - include navigable fields except the description (the default is *navigable for search)
*all,-comment - include everything except comments
So basically, the request is should be like that:
curl -u admin:admin -X POST localhost:50813/rest/api/2/search -H "Content-Type: application/json" -d '{"jql":"updated > -1d"}'

Dart : At the end of the tutorial, I don't know how to check that the app is working

https://dartfrog.vgv.dev/docs/tutorials/todos#summary
I got to this section, but I don't know how to get it to work at the end, so I can't get it to work.
in my browser
http://localhost:8080/todos
When I access the above url, [] is displayed, so I think it's working.
# Update a specific todo by id
curl --request PUT \
--url http://localhost:8080/todos/<id> \
--header 'Content-Type: application/json' \
--data '{
"title": "Take out trash!",
"isCompleted": true
}'
How can I check that the above part works?
The line you see there is a command you are supposed to run on your commandline.
If you use a newer version of windows you probably have curl already, if not, see How do I install and use cURL on Windows?
So you open your command prompt and enter
curl --request PUT --url http://localhost:8080/todos/<id> --header 'Content-Type: application/json' --data '{ "title": "Take out trash!", "isCompleted": true }'
where I guess the <id> part needs to be an id. So for example 1.
Please note that that is a tutorial for a backend in Dart. They are not commonly called an app. If you are looking to build a nice app for your device or webbrowser, with ui controls like input boxes and buttons, you are reading the wrong tutorial.

Create POST Request with Postman

This curl is working fine and returns the token as expected:
curl -X POST -H "X-Requested-With: XMLHttpRequest" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{ "username": "pere.peris#gmail.com","password": "password" }' "http://75.90.255.68:1133/canPeris/auth"
But when I do the same call using Postman app I get a 401 Unauthorized as a return value
You should add the missing JSON inside the Body . click Raw combo box and add
{ "username": "pere.peris#gmail.com","password": "password" }
You can use the function in Postman to generate curl:
https://www.getpostman.com/docs/v6/postman/sending_api_requests/generate_code_snippets
On the right side under "Send" and "Save" just hit the Code Button/Link. Then select in the next window in the drop down cURL. So you see what cURL would be generated and compare it with the command line.
The -d option is described here: https://curl.haxx.se/docs/manpage.html#-d

watson machine learning api - token refresh 400 error

I've successfully generated a token with the GET /v3/identity/token API. I now want to be able to leverage the PUT API to keep the token active.
I am trying this curl command:
curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' -d '<token-value>' 'https://ibm-watson-ml.mybluemix.net/v3/identity/token' -v -i --basic --user <username>:<password>
I get a 400 error stating:
For request 'PUT /v3/identity/token' [Invalid Json: Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value at [Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1#18bd12ef; line: 1, column: 3]]
The token returned from the get request has the dash character in it, along with other non-alphnumeric values.
Does the token from the get request need to be parsed? what am I missing?
You need to set your content-type to application/json. But -d sends the Content-Type application/x-www-form-urlencoded, which maybe is not accepted on IBM side.
But, seems like your JSON (token) are in the incorrect format.
The token value needs to be the following format (JSON):
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"
}
And you need to follow the example of sent correctly the format:
curl -H 'Content-Type: application/json' -X PUT \
-d '{"token":"yourToken"}' \
https://ibm-watson-ml.mybluemix.net/v3/identity/token
See the official reference.

Cant access PFUsers from Parse

I am new to parse and ios development.
I want to use Parse for User management of an IOS app. With the help of documentation (https://parse.com/docs/ios/guide#users-signing-up) I was able to signup some sample users and I have the following in Parse app.
Then I want to retrieve all users (or query for specific) with following documentation help.
var query = PFUser.query()
query.whereKey("gender", equalTo:"female")
var girls = query.findObjects()
I was expected to receive an array of size 3 but surprisingly didn't receive any.
Later I figured out I can user API console feature of Parse and tried use it to receive PFUser objects. I received zero results.
Later I tried with sample table and I was successfully add, retrieve Objects to the table.
Not sure If I need to anything special for me to use PFUser.
I have tested using API Console and its working on my side. I have one entry in User table having gender = male.
I fired following curl query to retry all the users
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
https://api.parse.com/1/users
Result from the above query is:
{"results":[{"gender":"male","createdAt":"2015-12-10T06:00:40.368Z","email":"sam07it22#gmail.com","objectId":"1KbxpYgeUb","updatedAt":"2015-12-10T06:01:32.885Z","username":"sam07it22#gmail.com"}]}
Now, I'm going to add Condition in above query to fetch records having gender = female. As per data expected result should have zero records
For gender = female
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
--data-urlencode 'where={"gender":"female"}' \
https://api.parse.com/1/users
Output:
{"results":[]}
For gender = male
curl -X GET \
-H "X-Parse-Application-Id: <#your-application-key>" \
-H "X-Parse-REST-API-Key: <#your-rest-api-key>" \
-G \
--data-urlencode 'where={"gender":"male"}' \
https://api.parse.com/1/users
Output:
{"results":[{"gender":"male","createdAt":"2015-12-10T06:00:40.368Z","email":"sam07it22#gmail.com","objectId":"1KbxpYgeUb","updatedAt":"2015-12-10T06:01:32.885Z","username":"sam07it22#gmail.com"}]}
NOTE:
Don't forget to replace your API KEY and REST API KEY
ACL permissions has done the trick. ACL permissions has to be "public read" for them to be accessible. Here is more info about ACL in parse https://parse.com/docs/ios/guide#security-object-level-access-control

Resources