Query instance metadata

The instance SPARQL endpoint answers questions about a TriplyDB instance itself: which datasets an account owns, which saved queries run against a dataset, which assets were uploaded last week, which flow runs failed. One query there can combine what would otherwise take many HTTP API requests. Every class and property it exposes is listed in Instance SPARQL endpoint.

On this page, API stands for the instance's API address, such as api.triplydb.com.

Send a query to the endpoint

Send the query to https://API/sparql. To see what you see when logged in, add an API token in an Authorization: Bearer header:

curl -H "Authorization: Bearer TRIPLYDB_TOKEN" \
     --data-urlencode "query=select * { ?dataset a <https://triplydb.com/Triply/triplydb/def/Dataset> }" \
     https://API/sparql

Leave the header out and you get what an anonymous visitor sees: public resources only.

Query it from a dataset

To combine instance metadata with the data in a dataset, wrap the metadata part of a query in a service clause and run it on the dataset. The endpoint answers with your access, as if you had sent your own token:

prefix datasetDef: <https://triplydb.com/Triply/triplydb/def/Dataset/>

select ?dataset ?name where {
  service <https://API/sparql> {
    ?dataset datasetDef:name ?name .
  }
}
limit 10

Write a query

Find the property in the reference. A property is named by its class and the key that holds the value in the API's JSON, so if you know the API you can guess most of them: the name of a dataset is datasetDef:name, with datasetDef: standing for https://triplydb.com/Triply/triplydb/def/Dataset/.

Follow an IRI to the resource it names. A dataset's owner is the IRI of the account, so datasetDef:owner/accountDef:accountName reaches the owner's short name.

Escape the slash in a nested property. A key such as uploadedBy/accountName contains a /, which SPARQL reads as a property path unless you escape it: assetVersionDef:uploadedBy\/accountName.

Match list items with rdf:rest*/rdf:first. Tags, prefixes, asset versions and other lists are rdf:Lists, so datasetDef:tags/rdf:rest*/rdf:first ?tag binds ?tag to each tag in turn.

Examples

Each example answers one question about the instance with a complete query for the endpoint.

List the datasets of an account

List all datasets owned by the academy group, with their licenses where one is filled in:

prefix accountDef: <https://triplydb.com/Triply/triplydb/def/Account/>
prefix datasetDef: <https://triplydb.com/Triply/triplydb/def/Dataset/>

select ?dataset ?name ?license where {
  ?owner accountDef:accountName "academy" .
  ?dataset datasetDef:owner ?owner ;
           datasetDef:name ?name .
  optional { ?dataset datasetDef:license ?license }
}
order by ?name

Find datasets with a tag

List all datasets tagged geo:

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix datasetDef: <https://triplydb.com/Triply/triplydb/def/Dataset/>

select ?dataset ?name where {
  ?dataset datasetDef:tags/rdf:rest*/rdf:first "geo" ;
           datasetDef:name ?name .
}

List saved queries and their SPARQL

List all saved queries owned by the academy group, with their SPARQL text and the dataset each one runs against:

prefix triplyDef: <https://triplydb.com/Triply/triplydb/def/>
prefix accountDef: <https://triplydb.com/Triply/triplydb/def/Account/>
prefix queryVersionDef: <https://triplydb.com/Triply/triplydb/def/QueryVersion/>

select ?name ?version ?dataset ?queryText where {
  ?query a triplyDef:QueryVersion ;
         queryVersionDef:owner/accountDef:accountName "academy" ;
         queryVersionDef:name ?name ;
         queryVersionDef:version ?version ;
         queryVersionDef:dataset ?dataset ;
         queryVersionDef:requestConfig/queryVersionDef:requestConfig\/payload/queryVersionDef:requestConfig\/payload\/query ?queryText .
}

Find recent asset uploads

Show the ten most recent asset uploads, with the size of each file and who uploaded it:

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix assetDef: <https://triplydb.com/Triply/triplydb/def/Asset/>
prefix assetVersionDef: <https://triplydb.com/Triply/triplydb/def/AssetVersion/>

select ?fileName ?size ?uploadedAt ?uploader where {
  ?asset assetDef:assetName ?fileName ;
         assetDef:versions/rdf:rest*/rdf:first ?version .
  ?version assetVersionDef:fileSize ?size ;
           assetVersionDef:uploadedAt ?uploadedAt .
  optional { ?version assetVersionDef:uploadedBy/assetVersionDef:uploadedBy\/accountName ?uploader }
}
order by desc(?uploadedAt)
limit 10

Find failed flow runs

List the flow runs that failed, newest first, with the flow each belongs to and the reason it failed:

prefix flowDef: <https://triplydb.com/Triply/triplydb/def/Flow/>
prefix flowRunDef: <https://triplydb.com/Triply/triplydb/def/FlowRun/>

select ?flowLabel ?startedAt ?message where {
  ?run flowRunDef:status "failed" ;
       flowRunDef:createdAt ?startedAt ;
       flowRunDef:blueprint/flowDef:label ?flowLabel .
  optional { ?run flowRunDef:statusMessage ?message }
}
order by desc(?startedAt)

Check the instance version

Show which TriplyDB version the instance runs, and the addresses of its console and API:

prefix triplyDef: <https://triplydb.com/Triply/triplydb/def/>
prefix instanceDef: <https://triplydb.com/Triply/triplydb/def/Instance/>

select ?version ?consoleUrl ?apiUrl where {
  ?instance a triplyDef:Instance ;
            instanceDef:version ?version ;
            instanceDef:consoleUrl ?consoleUrl ;
            instanceDef:apiUrl ?apiUrl .
}