1

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?

Stratos K
  • 341
  • 2
  • 14
  • 1
    did you try with a leading `$` char to indicate that the HTTP param is a query variable? – UninformedUser Aug 05 '22 at 18:13
  • 2
    *"one of the query params is also $ which specifies variable bindings."* As @UninformedUser mentioned, you'd probably need `&$customerId="123"` for this to work. Otherwise, it'd be impossible to bind a value for a variable called `query`, since `?query=...` is already used for the query itself. – Joshua Taylor Aug 05 '22 at 18:38
  • Note that you could also use a `values` block within the query: `select ... where { ... values ?customerId { "123" } }`. – Joshua Taylor Aug 05 '22 at 18:40
  • Duh, both of you are absolutely correct, I needed to add a `$` in front of the param name. Many thanks! – Stratos K Aug 08 '22 at 08:06

1 Answers1

0

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"
Stratos K
  • 341
  • 2
  • 14