I am trying to submit a SPARQL query to a local repository on Ontotext GraphDB via its REST API. According to the documentation, one of the query params is also $<varname>
which specifies variable bindings.
Suppose we have a repository called testrepo
that contains customers, each of whom has a unique customerID
. Submitting the following query:
PREFIX : <http://www.example.com/>
SELECT * WHERE {
?customer a :Customer ;
:hasID ?customerID .
}
as a GET request with the respective variable binding customerID = "123"
unfortunately retrieves all the customers and not the specific one.
Here is the request:
http://localhost:7200/repositories/testrepo?query=PREFIX%20%3A%20%3Chttp%3A%2F%2Fwww.example.com%2F%3E%0ASELECT%20*%20WHERE%20%7B%0A%09%3Fcustomer%20a%20%3ACustomer%20%3B%0A%20%20%20%20%20%20%20%20%20%20%20%3AhasID%20%3FcustomerID%20.%0A%7D%20&customerID="123"
So, what am I doing wrong?
SOLVED: As specified by UninformedUser and Joshua Taylor, I should have added a $
in front of the param name.
The correct request is the following:
http://localhost:7200/repositories/testrepo?query=PREFIX%20%3A%20%3Chttp%3A%2F%2Fwww.example.com%2F%3E%0ASELECT%20*%20WHERE%20%7B%0A%09%3Fcustomer%20a%20%3ACustomer%20%3B%0A%20%20%20%20%20%20%20%20%20%20%20%3AhasID%20%3FcustomerID%20.%0A%7D%20&$customerID="123"