I'm trying to run DELETE queries from the GraphDB REST API with Python requests module, without luck.
SELECT queries with requests.get()
work fine:
query = "http://localhost:7200/repositories/myreponame?name=&infer=true&sameAs=false&query=SELECT ?s ?p ?o
WHERE {
?s ?p ?o .
}
"
response = requests.get(query, headers = {"Authorization" : token})
But whenever I switch to a DELETE query, it won't work.
If I use the DELETE query with requests.get()
I get this error:
query = "http://localhost:7200/repositories/myreponame?name=&infer=true&sameAs=false&query=DELETE {
?s ?p ?o .
}
WHERE {
?s ?p ?o .
}
"
MALFORMED QUERY: Encountered " "delete" "DELETE "" at line 1, column 1.
Was expecting one of:
"base" ...
"prefix" ...
"select" ...
"construct" ...
"describe" ...
"ask" ...
If I use the DELETE query with requests.delete()
instead, I get:
Repository delete error: query supplied with request
What am I doing wrong?
I'm accessing the API with admin privileges, so that is not the issue.
EDIT: Based on UninformedUser's comment I tried the switching to a POST request, and modifying the URL from query to update. Also added the appropriate content type as described here:
query = "http://localhost:7200/repositories/myreponame?name=&infer=true&sameAs=false&update=DELETE {
?s ?p ?o .
}
WHERE {
?s ?p ?o .
}
"
response = requests.post(query, headers = {"Authorization" : token, "Content-Type": "application/x-www-form-urlencoded"})
Now getting the following error:
Missing parameter: query
CodePudding user response:
Turns out that I was missing a specific requirement from GraphDB: for updates it's necessary to append /statements
right after the repository ID:
query = "http://localhost:7200/repositories/myreponame/statements?name=&infer=true&sameAs=false&update=DELETE {
?s ?p ?o .
}
WHERE {
?s ?p ?o .
}
"
response = requests.post(query, headers = {"Authorization" : token, "Content-Type": "application/x-www-form-urlencoded"})