freme-project / e-Link

Apache License 2.0
0 stars 0 forks source link

PUT new template #60

Closed pheyvaer closed 9 years ago

pheyvaer commented 9 years ago

I get a 400 when trying the provided example:

{
  "query":"PREFIX dbpedia: <http://dbpedia.org/resource/>
      PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
      PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
      PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
      CONSTRUCT
      {
        ?museum <http://xmlns.com/foaf/0.1/based_near> <@@@entity_uri@@@> .
      }
      WHERE
      {
          <@@@entity_uri@@@> geo:geometry ?citygeo .
          ?museum rdf:type <http://schema.org/Museum> .
          ?museum geo:geometry ?museumgeo .
          FILTER (<bif:st_intersects>(?museumgeo, ?citygeo, 10))
      }
      LIMIT 10",
"endpoint":"http://dbpedia.org/sparql/",
"label":"template title",
"description":"template description",
"endpointType":"sparql",
"visibility":"public"
}
jnehring commented 9 years ago

Please share the whole request, e.g. as a CURL. And also the full response.

pheyvaer commented 9 years ago

I just executed the example from the documentation.

Curl

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "
{
  \"query\":\"PREFIX dbpedia: 
      PREFIX dbpedia-owl: 
      PREFIX rdf: 
      PREFIX geo: 
      CONSTRUCT
      {
        ?museum  <@@@entity_uri@@@> .
      }
      WHERE
      {
          <@@@entity_uri@@@> geo:geometry ?citygeo .
          ?museum rdf:type  .
          ?museum geo:geometry ?museumgeo .
          FILTER ((?museumgeo, ?citygeo, 10))
      }
      LIMIT 10\",
\"endpoint\":\"http://dbpedia.org/sparql/\",
\"label\":\"template title\",
\"description\":\"template description\",
\"endpointType\":\"sparql\",
\"visibility\":\"public\"
}" "http://api-dev.freme-project.eu/current/e-link/templates/?informat=application%2Fjson&outformat=application%2Fjson"

Response body

{
  "exception": "eu.freme.broker.exception.BadRequestException",
  "path": "/e-link/templates/",
  "message": "Unterminated string at 61 [character 0 line 4]",
  "error": "Bad Request",
  "status": 400,
  "timestamp": 1446044909025
}
m1ci commented 9 years ago

There are several problems with the request:

1) Unterminated string at 61 means that the JSON is not correctly formatted. Not sure how here the newline characters are encoded, but I suggest using \n or send the JSON from file using -d @template.json

2) there is not endpointType field in the JSON, but type

3) visibility should be send as query parameter and not as part of the JSON object.

4) you need to be authenticated before you submit a template for creation. In other words, you need to create a user, and then request for a token and submit the token using the token parameter when creating a template.

Here is a valid cURL request

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d @template-pieter.txt "http://api-dev.freme-project.eu/current/e-link/templates/?informat=application%2Fjson&outformat=application%2Fjson&token=YOUR_TOKEN"

Here is your template attached template-pieter.txt

m1ci commented 9 years ago

hey Pieter, I was just reading https://github.com/freme-project/Documentation/issues/115 and realized that point 2) and 3) are not valid, so:

1) Unterminated string at 61 means that the JSON is not correctly formatted. Not sure how here the newline characters are encoded, but I suggest using \n or send the JSON from file using -d @template.json

2) endpointType is correctly set and it is part of the JSON

3) visibility is correctly set and it is part of the JSON

4) stays the same.

Sorry for the noise I just wasn't informed about the changes.

Sending the corrected template attached template-pieter.txt

pheyvaer commented 9 years ago

@jnehring do you know about the first problem? Because I assume that when (new) users test the API using the documentation this should work, no?

jnehring commented 9 years ago

The JSON in the code example is not correct. There are no newlines in JSON. Newlines are escaped with \n in JSON.

We will handle this issue in freme-project/Documentation#125

jnehring commented 9 years ago

@pheyvaer can you please try again? We updated the documentation.

pheyvaer commented 9 years ago

@jnehring this works now. Is it also possible to provide an input field to add a token to the request?

jnehring commented 9 years ago

You can find that field on the bottom of the full api documentation page. Its a new feature.