IBM Watson Personality Insights Not returning json profile - watson

If I follow the instructions at this website, the first two (profile.txt and profile.json) should return a .json profile object. Instead I am just getting an output of raw numbers. This was working a few weeks ago so I'm unsure what has changed?
https://console.bluemix.net/docs/services/personality-insights/getting-started.html#getting-started-tutorial

So it turns out for whatever reason, it is returning the raw text values by default, NOT the structured JSON file as specified in the tutorial. An issue has been raised, however in the meantime you can simply add:
--header "Accept: application/json"
This will ensure you get the structured json file.

Related

Ruby on Rails basic use of RiotGames API (need explanation, solution already found)

First you must know I'm a total beginner, I'm trying to learn so I almost don't know anything.
On the basic page of the API, there is a curl command used as an example to show us how to make requests.
I'm using Ruby on Rails so I used "curl-to-ruby" website to translate it, but it did not work as expected.
I wanted it to show me this :
uri = URI.parse("REQUEST_URL")
response = JSON.parse(Net::HTTP.get(uri))
Instead I got this :
uri = URI.parse("REQUEST_URL")
response = Net:HTTP.get_response(uri)
I don't understand any of this, I thought I wouldn't need to and just use "curl-to-ruby", but apparently I really need to get this.
Would you please try to explain me ?
Or give me links ?
Or matters to read (curl, API, http) ?
Thank you very much, have a nice day.
It's because that command doesn't return just the content, it returns the whole HTTP response object including headers and body. You need to extract the response body and parse that using JSON.parse(), e.g.
JSON.parse(response.body)
See documentation here: https://docs.ruby-lang.org/en/2.0.0/Net/HTTP.html#method-c-get_response
(Also, there is nothing in the cURL command which would hint to the converter that the content-type of the response was expected to be JSON (e.g. perhaps an "accepts" header or something), so even if it were able to produce extra code adding the JSON.parse part, it has no way of knowing that it would be appropriate to do so in this case.)

Medium API: method missing to list posts?

I see a lot of useful methods in the API, but I don't find any method to list all my Posts, or all the posts from within a publication. Is this intentional?
Thought it would be something really obvious to exist in the API. Or am I missing something?
Got it, just use the RSS feed instead.
I wrapped a Github package by #mark-fasel into a Clay microservice that enables you to do exactly this:
Simplified Return Format:
https://clay.run/services/nicoslepicos/medium-get-users-posts-simple
What Medium actually returns at the endpoint
https://clay.run/services/nicoslepicos/medium-get-users-posts
I put together a little fiddle, since a user was asking how to use the endpoint in HTML to get the titles for their last 3 points:
https://jsfiddle.net/h405m3ma/1/
You can call the API as:
curl -i -H "Content-Type: application/json" -X POST -d '{"username":"nicolaerusan"}' https://clay.run/services/nicoslepicos/medium-get-users-posts-simple
You can also use it easily in your node code using the clay-client npm package and just write:
Clay.run('nicoslepicos/medium-get-users-posts-simple', {"username":"usernameValue"}) .then((result) => {
// Do what you want with returned result console.log(result);
})
If you need to generally pull down an RSS feed, here's a microservice for that:
https://clay.run/services/nicoslepicos/rss-to-json

Posting attachments to Slack API

So I just understood that the Slack Web API does not support JSON data over POST. Which means I have to encode my complex and nested JSON object to fit in query parameters over GET. Problem is, the attachements don't seem to work. Does anyone have a solution ?
So I just understood that the Slack Web API does not support JSON data over POST. Which means I have to encode my complex and nested JSON object to fit in query parameters over GET.
I'm not sure I follow what you mean. You can certainly use POST. The body of a Slack API call should be form-encoded, but parameter values are sometimes JSON (as is the case for attachments).
Here's a working curl command that uses HTTP POST to post a message with a simple attachment.
$ curl -d token=<REDACTED> -d channel=<REDACTED> \
-d text="This is the main text." \
-d attachments='[{"text": "This is an attachment."}]' \
https://slack.com/api/chat.postMessage
I'd recommend using POST, but GET also works fine. If you fill in the values in https://api.slack.com/methods/chat.postMessage/test, the tool will give you a URL at the bottom that you can use with HTTP GET.

Unable to set due_on=null

I'm trying to remove a due date from a task using the following request:
curl --request PUT -u <KEY>: https://app.asana.com/api/1.0/tasks/<TASKID> -d "due_on=null"
and receive
{"errors":[{"message":"due_on: Day must be in yyyy-mm-dd format, not: null"}]}
What's the correct way to do it?
(I work at Asana)
This is supposed to work - it appears to be a bug. This should be fixed in our push today (11/20/2012). Thanks for reporting the problem!
Generally, in the API there are some fields which can take on the value of null in the JSON. When you use form-urlencoded parameters instead of a JSON content type, none of the values have specific types - they all come in as strings. In some places we weren't consistent about treating the string "null" as a real null value where it makes sense, like for due dates.

Posting XML to Rails

I am trying to
1) post some XML to my Rails App (without using forms)
2) have my Rails App then parse the posted XML to create entries within my database
For example, I'd like to post
<transaction>
<date>12-01-2010</date>
<amount>1.00</amount>
</transaction>
<transaction>
<date>12-02-2010</date>
<amount>2.00</amount>
</transaction>
Assuming I have a transaction controller. I'd then like to create an "upload" action that would allow me to parse the snippet above and create entries within my database.
From my research it seems like 1) can be accomplished with curl. But I'm not sure if that is right, because I don't know what URI to point the curl command to.
I am also not clear how to get the XML data within the "upload" action of my controller.
Any help would be appreciated.
Thank you!
You have to set Header Content-type, send as POST request and then you have only worry about the XML posted content
Here is a example of how to post xml by using curl
curl -X POST -H "Content-Type:text/xml" -d "<xml>Your XML Data</xml>" "http://your url"
XML parameter parser is removed in Rails 4, so if you're using Rails 4, you need to install actionpack-xml-parser gem first, refer to https://github.com/rails/actionpack-xml_parser

Resources