Query Protocol Issue

Hi Stardog Community,

I’m encountering an issue when querying a Stardog SPARQL endpoint and would appreciate your insights or suggestions. Below are the details:

Endpoint:
https://sd-d8db509a.stardog.cloud:5820/JTH-Product-Data

Problem Description

While performing SPARQL queries from different clients and environments, I noticed inconsistent behavior regarding response formats:

  1. Using the SERVICE keyword in GraphDB:
SELECT * WHERE {  
    SERVICE <https://sd-d8db509a.stardog.cloud:5820/JTH-Product-Data> {  
        <http://example.org/fagerhult_notor_product_data#7320046635763> ?property ?value .  
    }  
}

Result:
500: Error Query evaluation error: Unsupported Media Type

  1. Using dotNetRDF's SparqlRemoteEndpoint.QueryWithResultSet method:
SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri("https://sd-d8db509a.stardog.cloud:5820/JTH-Product-Data"));  
endpoint.Credentials = new System.Net.NetworkCredential("**user**", "**pwd**");  
SparqlResultSet results = endpoint.QueryWithResultSet("SELECT ?property ?value WHERE { <http://example.org/fagerhult_notor_product_data#7320046635763> ?property ?value }");

Result:
Exception: "Unable to Parse a SPARQL Result Set from the provided XML since the Document Element is not a element!"

  1. Using dotNetRDF's SparqlRemoteEndpoint.QueryRaw method:
    Observation:
    The raw HTTP response has a Content-Type header set to text/turtle.

I also tried setting the Accept header explicitly to application/sparql-results+json, but the response format didn’t change and remained text/turtle.

Working Solution

The only method that worked was using the StardogConnector class from dotNetRDF:

StardogConnector connector = new StardogConnector("https://sd-d8db509a.stardog.cloud:5820/JTH-Product-Data", "**user**", "**pwd**");  
SparqlResultSet results = connector.Query("SELECT ?property ?value WHERE { <http://example.org/fagerhult_notor_product_data#7320046635763> ?property ?value }");

Key Question:

According to the SPARQL 1.1 Protocol, the specified response formats for SPARQL queries should include XML, JSON, and CSV/TSV.

Why is Stardog returning text/turtle instead of one of the standard formats?

Is there a way to enforce the response format (e.g., JSON or XML) when querying the endpoint?

Any guidance or suggestions would be greatly appreciated!

Thanks in advance!

Best regards,
Rahel

Hi,

That is indeed odd behavior, especially since text/turtle isn't even a valid response type for a SELECT query. Do either of the first two methods work if you add /query to the end of the URL?

Regardless, could you share an example of the text/turtle response that you're getting? My instance is defaulting to application/sparql-results+xml

output.ttl (375.3 KB)
Thank you for your response. Attached is the stream returned. Very strange?
The query is "SELECT ?property ?value WHERE {http://example.org/fagerhult_notor_product_data#7320046635763 ?property ?value }"

And the actual request as encoded by dotNetRDF:
"https://sd-d8db509a.stardog.cloud:5820/JTH-Product-Data?query=SELECT+%3Fproperty+%3Fvalue+WHERE+{<http%3A%2F%2Fexample.org%2Ffagerhult_notor_product_data%237320046635763>+%3Fproperty+%3Fvalue+}"

Hi,
Thank you for your response. Could you kindly review what @Lars_Wikstrom has written? We are working on the same project and would greatly appreciate your support.

Kind regards,
Rahel

As suggest by @Stephen, make sure to add the /query to the endpoint URL.
That is, should be something like:

https://sd-d8db509a.stardog.cloud:5820/JTH-Product-Data/query?query=...

Best regards
Lars

Thank you! Now it works fine with the standard sparql calls from dotNetRDF. I still get an error "Query evaluation error: org.eclipse.rdf4j.query.QueryEvaluationException: org.eclipse.rdf4j.query.resultio.QueryResultParseException: File does not contain a binary RDF table result" when trying to query as SERVICE from GraphDB, but I guess that I will have to take that thing with those guys.