Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The API supports only HTTP POST calls. GET, HEAD, and other methods are not supported, and will return a response code of 405 Method Not Allowed.

Parameters

namevaluenotes
emailthe email address of a VIVO adminstrator administrator account
passwordthe password of the VIVO administrator account
updateA SPARQL Update requestOptional. If used, request content type must be set to application/x-www-form-urlencoded and the update data must be URL-encoded.

The syntax for a SPARQL Update request is described on the World Wide Web Consortium site at http://www.w3.org/TR/2013/REC-sparql11-update-20130321/

...

The API requires that you specify a GRAPH in your SPARQL update request. Insertions or deletions to the default graph are not supported.

Sending data via the POST body vs the 'update' parameter

The API supports sending data via an 'update' parameter. Prior to v1.13.0, this was the only method of sending SPARQL update data. Since 1.13.0, VIVO also supports sending data via the POST message body. To use this method, you must set the request content type to application/sparql-update. This method parses the data as an input stream and may offer a performance improvement for large amounts of data. 

Response Codes

CodeReason
200 OKSPARQL Update was successful.
400 Bad RequestHTTP request content type was set to application/x-www-form-urlencoded and did not include an an update parameter.
The SPARQL Update request did not specify a GRAPH.
The SPARQL Update request was syntactically incorrect.
403 ForbiddenHTTP request did not include an email parameter.
HTTP request did not include a password parameter.
The combination of email and password is not valid.
The selected VIVO account is not authorized to use the SPARQL Update API.
405 Method Not AllowedIncorrect HTTP method; only POST is accepted.
500 Internal Server ErrorVIVO could not execute the request; internal code threw an exception.

...

This example inserts a single RDF statement into the data model.

Insert via the POST body

Code Block
languagebash
curl -i --request POST 'http://localhost:8080/vivo/api/sparqlUpdate?email=vivo_root@mydomain.edu&password=Password' \
--header 'Content-Type: application/sparql-update' \
--data-raw 'INSERT DATA { GRAPH <http://vitro.mannlib.cornell.edu/default/vitro-kb-2> { 
 <http://test.domain/ns#book1> 
          <http://purl.org/dc/elements/1.1/title> 
          "Fundamentals of Compiler Design" .  
} }'

Insert using the 'update' parameter

Code Block
languagebash
curl -i -d 'email=testAdmin@mydomain.edu' -d 'password=Password' -d '@insert.sparql' 'http://localhost:8080/vivo/api/sparqlUpdate'

...

This example removes the previous statement, and inserts a replacement.

Modify via the POST body

Code Block
languagebash
curl -i --request POST 'http://localhost:8080/vivo/api/sparqlUpdate?email=vivo_root@mydomain.edu&password=Password' \
--header 'Content-Type: application/sparql-update' \
--data-raw 'DELETE DATA { GRAPH <http://vitro.mannlib.cornell.edu/default/vitro-kb-2> { 
 <http://test.domain/ns#book1> 
          <http://purl.org/dc/elements/1.1/title> 
          "Fundamentals of Compiler Design" .  
} }

INSERT DATA { 
   GRAPH <http://vitro.mannlib.cornell.edu/default/vitro-kb-2> { 
      <http://test.domain/ns#book1> 
          <http://purl.org/dc/elements/1.1/title> 
          "Design Patterns" . 
    } 
}'

Modify via the update parameter

Code Block
languagebash
curl -i -d 'email=testAdmin@mydomain.edu' -d 'password=Password' -d '@modify.sparql' 'http://localhost:8080/vivo/api/sparqlUpdate'

...

This example removes the modified statement.

Delete via the POST body

Code Block
languagebash
curl -i --request POST 'http://localhost:8080/vivo/api/sparqlUpdate?email=vivo_root@mydomain.edu&password=Password' \
--header 'Content-Type: application/sparql-update' \
--data-raw 'DELETE DATA { GRAPH <http://vitro.mannlib.cornell.edu/default/vitro-kb-2> { 
 <http://test.domain/ns#book1> 
          <http://purl.org/dc/elements/1.1/title> 
          "Design Patterns" .  
} }'

Delete via the update parameter

Code Block
languagebash
 curl -i -d 'email=testAdmin@mydomain.edu' -d 'password=Password' -d '@delete.sparql' 'http://localhost:8080/vivo/api/sparqlUpdate'

...

If you want to remove a named graph entirely, you can use the SPARQL CLEAR method. 

Delete via the POST body

Code Block
languagebash
curl -i --request POST 'http://localhost:8080/vivo/api/sparqlUpdate?email=vivo_root@mydomain.edu&password=Password' \
--header 'Content-Type: application/sparql-update' \
--data-raw 'CLEAR GRAPH IRIRef'

Clear via the update parameter

Code Block
titleCLEAR example
curl -i -d 'email=USER' -d 'password=PASSWORD' -d 'update=CLEAR GRAPH IRIRef' 'http://localhost:8080/vivo/api/sparqlUpdate'

...

Code Block
languagexml
titleserver.xml
<Connector port="8080" protocol="HTTP/1.1"
    connectionTimeout="20000"
   URIEncoding="UTF-8"
   redirectPort="8443" 
   maxPostSize="10485760"/>

Advanced Use

Since v1.13.0, VIVO supports the use of the advanced parameters using-graph-uri and using-named-graph-uri. You could use these parameters to query a graph, while simultaneously creating new triples based on the query results. For example:

Code Block
languagebash
curl --location --request POST 'http://localhost:8080/vivo/api/sparqlUpdate?email=vivo_root@mydomain.edu&password=Password&using-graph-uri=http://vitro.mannlib.cornell.edu/default/vitro-kb-2' \
--header 'Content-Type: application/sparql-update' \
--data-raw 'INSERT {
  GRAPH <http://example.com/new-test-graph> {
    ?s <http://example.com/test> "using-graph-uri worked!" .
  }
}
WHERE
  {  ?s  a <http://purl.org/ontology/bibo/Journal> }'

would query the kb-2 graph for subjects of type bibo:Journal, then insert a new triple into the http://example.com/new-test-graph graph based on the resulting subject URIs. Some discussion on using these parameters can be found on this Stack Overflow page.

Enabling the API


Note

Before enabling the SPARQL update handler, you should secure the URL api/sparqlUpdate with HTTPS. Otherwise, email/password combinations will be sent across the network without encryption. Methods for securing the URL will depend on your site's configuration.

...