Why doesn't the Apiary Console give a correct response for this API Blueprint? - apiblueprint

I'm trying to create a simple demo of how API Blueprint works with Apiary.io. For the demo, I wanted to put an endpoint from the Mashape Weather API into blueprint.
Here's the attempt:
http://docs.weatherapi3.apiary.io/#reference/weather/weather-data/get-the-weather-data?console=1
It seems to work (meaning, the Try it out button in the Console gives a response), but I get this result:
{
"query": {
"count": 0,
"created": "2015-06-21T11:12:06Z",
"lang": "en-US",
"results": null
}
}
The same result passed via cURL does give a correct response, which is an output of the weather.
Is there something I am misconfiguring in the blueprint?
Alternatively, does Mashape block calls from Apiary.io?
Here's the blueprint:
FORMAT: 1A
HOST: https://simple-weather.p.mashape.com
# Weather API
Display Weather forecast data by latitude and longitude. Get raw weather data OR simple label description of weather forecast of some places.
# Weather API Root [/]
# Group Weather
Resources related to weather in the API.
## Weather data [/weatherdata{?lat}{?lng}]
### Get the weather data [GET]
Get the weather data in your area.
+ Parameters
+ lat: 55.749792 (required, number) - Latitude
+ lng: 37.632495 (required, number) - Longitude
+ Request JSON Message
+ Headers
X-Mashape-Authorization: {hidden in this post}
Accept: text/plain
+ Response 200 (application/json)
+ Body
[
{
"query": {
"count": 1,
"created": "2014-05-03T03:57:53Z",
"lang": "en-US",
"results": {
"channel": {
"title": "Yahoo! Weather - Tebrau, MY",
"link": "http://us.rd.yahoo.com/dailynews/rss/weather/Tebrau__MY/*http://weather.yahoo.com/forecast/MYXX0004_c.html",
"description": "Yahoo! Weather for Tebrau, MY",
"language": "en-us",
"lastBuildDate": "Sat, 03 May 2014 11:00 am MYT",
"ttl": "60",
"location": {
"city": "Tebrau",
"country": "Malaysia",
"region": ""
},
...//truncated for this post
}
}
}
}
}
]

There is a tiny mistake in Blueprint in GET parameters. Parameters should be written like: {?param1,param2} (See: URI Templates)
So if you just change
## Weather data [/weatherdata{?lat}{?lng}] to ## Weather data [/weatherdata{?lat,lng}] it works.

Related

How to handle JSON array response while using APIConsumer?

Using the APIConsumer contract we can feed data from API to the smart contract.
Eg: If the server response is:
{
"RAW":{"ETH":{"USD":{"VOLUME24HOUR": 10000,}}}
}
Then, data can be obtained as:
request.add("get", URL);
request.add("path", "RAW.ETH.USD.VOLUME24HOUR");
Similarly, If the server response contains some JSON array,
Eg:
{
"date":"530934083405834",
"results": [
{
"id": 9865,
"rank":1
},
{
"id": 9869,
"rank": 2
},
{
"id": 9866,
"rank": 3
}
]}
Then in this case is there a way to get the id of the rank 1 i.e results[0]["id"]?
To get results[0]["id"] your path in the request needs to be
request.add("path", "results.0.id");

How to mention array of object in hasura graphql action type?

How to define the Action type in Hasura graphql(console) for below given API response?
{
"data": [
{
"name": "Jordan Smith",
"id": 101,
"location": "Florida",
"speciality_id": 214
},
{
"name": "Cathy Morphy",
"id": 104,
"location": "london",
"speciality_id": 214
}
],
"count": 2 }
If you have control over what's in your API response, and can change it to just return an array of objects (what's inside data), then something like this should work:
type Query {
doctors(specialty_id: Int, search: String, limit: Int, offset: Int): [Doctor]
}
type Doctor {
name: String
id: Int
location: String
specialty_id: Int
}
If you don't have control over the API response, you'll need another layer (e.g. a serverless function or another server endpoint to request the data and transform the response into the format Hasura Actions can handle).
See also:
https://github.com/hasura/graphql-engine/issues/4806
https://hasura.io/docs/latest/graphql/core/actions/types/index.html#custom-graphql-types

google speech api response is empty, even with this example test

When I run the API explorer from this page i get a 200 OK response, but the response json doesn't have any transcription. What am i doing wrong?
API Explorer location:
https://cloud.google.com/speech/reference/rest/v1/speech/longrunningrecognize
Request parameters:
Default
Request body:
{
"config": {
"encoding": "FLAC",
"languageCode": "en-US",
"sampleRateHertz": 16000
},
"audio": {
"uri": "gs://cloud-samples-tests/speech/brooklyn.flac"
}
}
Response:
{
"name": "3497944051092250866"
}
i figured it out.
with longrunningrecognize you get back the name object and then you have to send a operations.get to retrieve your processed object.
this is explained here beautifully
https://medium.com/towards-data-science/tutorial-asynchronous-speech-recognition-in-python-b1215d501c64

Wrapping Data Structure in a data key API Blueprint / Apiary

So let's say I have a 200 response which body should be:
{
"data": [
{
"id": 1,
"title": "Activity 1"
},
{
"id": 1,
"title": "Activity 2"
}
]
}
I have managed to get this behavior of the response body by using this in API Blueprint.
+ Response 200 (application/json)
+ Attributes
+ data (array[Activity])
(Note that I can't add the data key to the data structure itself, because it's only present on the single response. If I need to nest an Activity inside another structure, it shouldn't have the data key.)
This doesn't seem right
The reason why I don't think it's the correct way of doing it, is beacuse of the JSON schema for this response which is:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"data": {
"type": "array"
}
}
}
Note how the actual activity is excluded.
How can I wrap my response in a data key properly, and have it reflected in both the body AND the schema?
You should use this line:
+ data(array[Activity], fixed-type)
The fixed-type keyword fixes the type of the items in the array.

What services can I use to fetch an image of a person based on their email address, without authentication

I know gravatar allows this, and I'd like to look into facebook, google plus, twitter, instagram, and anything else.
Do you guys know of any services like this?
EDIT: to clarify, by "without authentication" do I mean user authentication, I expect to use some sort of API
One possible approach, using Facebook Graph Api would be to perform a search against the name for users objects and also retrieve their pictures, using API version 2.2 it would be a call like:
GET graph.facebook.com
/search?q=miles davis&type=user&fields=id,name,picture
This would retrieve id, name and picture object for a search on miles davis, first results as example:
{
"data": [
{
"id": "805353876185303",
"name": "Miles Davis",
"picture": {
"data": {
"is_silhouette": true,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/v/t1.0-1/c15.0.50.50/p50x50/10354686_10150004552801856_220367501106153455_n.jpg?oh=XXXXXXXXXXXXXXXX&oe=XXXXXX&__gda__=XXXXXXX_XXXXXXXXXXXXX"
}
}
},
{
"id": "1572370603017419",
"name": "Miles Davis",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/v/t1.0-1/p50x50/1501761_1382020035385811_1384168153_n.jpg?oh=XXXXXXXXX&oe=XXXXXXXXXXX&__gda__=XXXXXX_XXXXXX"
}
}
}, ...........
The field is_silhouette is false if the user has a profile picure.

Resources