CumulusRDF Update Query - rest

I'm trying to insert data my CumulusRDF via REST.
Problem: If i'm doing a query, it works nice, with the GET method
Ex: A simple query:
select *
where
{
?s ?p ?o.
}
GET method:
curl -X GET --header 'Accept: application/sparql-results' 'http://localhost:9090/cumulus/sparql?query=select+*+where+%7B%3Fs+%3Fp+%3Fo.%7D&accept=text%2Fhtml'
But, when i try to insert data, it fails.
Query:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{
<http://example/book1> dc:title "Harry Potter".
}
POST method:
curl -i -X POST -H 'Content-Type: application/sparql-query' 'http://localhost:9090/cumulus/sparql?query=PREFIX+dc%3A+%3Chttp%3A%2F%2Fpurl.org%2Fdc%2Felements%2F1.1%2F%3E%0AINSERT+DATA%0A%7B+%0A++%3Chttp%3A%2F%2Fexample%2Fbook1%3E+dc%3Atitle+%22Harry+Potter%22.%0A%7D
Erro:
HTTP/1.1 400 Bad Request
What i'm doing wrong? CumulusRDF is instaled in a Docker with Apache Cassandra DB.

In SPARQL queries are not updates. There are two separate languages.
If you use the HTTP query string, content-type is irrelevant. It should be?update=.
Better is to POST with the update in the HTTP body and using
Content-Type: application/sparql-update

Related

Sonos Cloud API HTTP POST always returns 500

I'm trying to control my Sonos One (Gen 1) speaker through cloud APIs but all the POST request return 500 Internal Server Error without error message.
I generated an access_token as described in the documentation and was able to obtain information about the 'households' inside my network, finally both the group id and the player id.
I tried to obtain information about the status of the group by performing a GET on the following endpoint and it worked:
https://api.ws.sonos.com/control/api/v1/groups/{{group_id}}/playback
Same with other GET requestes (e.g. groupVolume).
The problem arise when I try to make a POST (e.g. changing the volume or playing an audioClip), it returns 500 Internal Server Error without any body.
For all the requests I am using Postman including as Headers:
Content-Type: application/json
Authorization: Bearer [token]
Content-Length: ??? (automatically inserted by postman)
while for the body of the change volume request I select the raw option and then select JSON(application/json) option.
The body is:
{
"volume": 80
}
The endpoint is the following: https://api.ws.sonos.com/control/api/v1/groups/{{group_id}}/groupVolume
I also tried controlling the player with node (Package) and it works.
Also tried to use Wireshark to see what requests the node-sonos package is performing but it seems it's not using the Cloud APIs.
I expect the player to change volume, but the API doesn't do anything and doesn't return any error message.
EDIT:
The cURL request from POSTMAN is the following:
curl -X POST \
https://api.ws.sonos.com/control/api/v1/players/<playerID>/audioClip \
-H 'authorization: Bearer XXX' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: XXX' \
-d '{
"appId": "edu.myInstitute.myName",
"clipType": "CUSTOM",
"name": "Test",
"streamUrl": "http://...mp3_file_url"
}'

What timestamp is used at Grafana Annotation HTTP API?

I'm trying to create an annotation in Grafana via the HTTP-API.
Due to the official docs I need to add a timestamp.
Example Request (from official docs)
POST /api/annotations HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"dashboardId":468,
"panelId":1,
"time":1507037197339,
"isRegion":true,
"timeEnd":1507180805056,
"tags":["tag1","tag2"],
"text":"Annotation Description"
}
But what kind of timestamp is it? I couldn't find any information about it.
I tested it with the current unix timestamp but the annotation will not show up.
Maybe helpful: My last alert from yesterday (13. Dez 2017, 07:02PM UTC+1) corresponds to "time": 1513101762000,.
Time should be in epoch in milliseconds based on their docs from the find method:
Query Parameters:
from: epoch datetime in milliseconds. Optional.
to: epoch datetime in milliseconds. Optional.
Check here for some code examples:
http://currentmillis.com/
Also, if you don't see them showing up on your dashboard be sure to use the header token authentication against the API and make sure you created the token API for the same org that the dashboard lives under.
A curl request would look similar too:
curl -i -XPOST -H "Authorization: Bearer <token>" -H "Accept: application/json" -H "Content-Type: application/json" -d '{"time":1513187523781,"isRegion":false,"tags":["test1"],"text":"Testing Annotations API"}' "https://grafana.host/api/annotations"

How to pass JSON as a query parameter in a HTTP request?

I am using RESTEasy stack to implement a REST based client and server. I have a service which handles POST request, like below:
#POST
#Path("/this")
#Produces(MediaType.APPLICATION_JSON)
#Consumes(MediaType.APPLICATION_JSON)
public String testPost(#QueryParam("thing") String thing) {
...
}
When I call from Postman or REST client the following URI:
http://ip:port/base/this?thing={"id":"abc"}
I always get the error as
java.net.URISyntaxException: Illegal character in query at index (pointing to =)
What is the reason for this?
If you're trying to parse a POST request, you should use #FormParam instead of #QueryParam. Then, you can make the post request doing something like this (using curl)
curl -i -X POST -H "Content-Type: application/json" -d thing="{\"id\":\"abc\"}" http://ip:port/base/this

Couchbase create document fails through sync-gateway public rest API

As per Couchbase Sync-Gateway REST API documentation here below mentioned cURL should create a document in the specified database.
Below is the generated cURL from Postman.
curl -X PUT -H "Cache-Control: no-cache" -H "Postman-Token: 498d0fb6-77ac-9335-2379-14258c6731c7" -d '' "http://192.168.244.174:4984/db/"
I also tried adding JSON to the body of the request.
But when I send the put request through Postman, instead of creating a new document, it tries to create a new database and the JSON response is
{
"error": "Precondition Failed",
"reason": "Database already exists"
}
Am I missing something or it was a bug? Is there any other way to create a document to sync gateway?
There is a mistake in the documentation.
As per documentation,
You can either specify the document ID by including the _id object in the request message body, or let the software generate an ID.
But Couchbase REST API does not seem to work like that (may be they are not updating their documentation regularly). You need to provide the id in the URL like /{db}/{id}.
The below cURL worked for me.
curl -X PUT -H "Content-Type: application/json" -H "Cache-Control: no-cache" -H "Postman-Token: 75ab844e-5130-708e-69e9-e87f878108b4" -d '{"name": "xxx",
"full_name": "xxx yyy"}' "http://192.168.244.174:4984/db/123"
JSON response is
{
"id": "123",
"ok": true,
"rev": "1-9324dabc947fc963a754b113d1215ac3"
}

ArangoDB graph operations via REST API

Is it possible to use AQL query language via REST API to make graph queries?
Thanks.
Yes, HTTP Query cursor API is the right API to do this. It allows executing AQL queries via HTTP.
Example (with a non-graph query):
curl \
-X POST \
--dump - \
"http://localhost:8529/_db/_system/_api/cursor" \
--data '{"query":"FOR u IN users RETURN u","count":true}'
You can put your AQL query string (using graph functions) into the query attribute of the request.
Bind parameters are optional. If used, they can be put into the optional bindVars attribute of the request:
curl \
-X POST \
--dump - \
"http://localhost:8529/_db/_system/_api/cursor" \
--data '{"query":"FOR u IN users FILTER u.name == #name RETURN u","bindVars":{"name":"foobar"}}'
Great! But this AQL bellow works fine in the AQL editor, but not it the REST.
curl -X POST --dump - http://localhost:8529/_db/database/_api/cursor --data '{query:LET from = (FOR p IN products FILTER p.name == "p1" RETURN p._id) LET to=(FOR p IN products FILTER p.name == "p2" RETURN p._id) INSERT { _from: from[0], _to: to[0], type: "RELATED" } INTO productsedge}'
HTTP/1.1 400 Bad Request
Server: ArangoDB
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
Content-Length: 82
{"error":true,"errorMessage":"expecting attribute name","code":400,"errorNum":600}