Authentication via API to SPARQL ENDPOINT

Hi @hwilliams,

I was reviewing the Openlink Virtuoso documentation on SPARQL authentication via API for a specific user. Is there documentation on how to perform a query using this method?



What is the URL to the documentation on the SPARQL authentication via API you are referring ?

@hwilliams I am looking at: 16.2.3.SPARQL Web Services & APIs

The Examples section from the document link show how to interact with the the SPARQL Endpoint restful API via curl. And if you specifically want to authenticate against and endpoint then the --user curl param can be used to provide the username and password as below:

curl --digest --user {username}:{password} "http://{hostname}:{port-number}/sparql-auth" --data-urlencode "query={SPARQL-query}"

Hi @hwilliams,

I found also an authentication via oauth but I can’t find where are generated this two parameters:
1. oauth_consumer_key
2. oauth_token

  curl ""

If you have VAL (Virtuoso Authentication Layer) installed, then the OpenID Connect (OIDC) and OAuth Protocol Virtualization, using Virtuoso details how to generate OAuth keys/tokens for use.

If VAL (Virtuoso Authentication Layer) is not installed then the Securing your SPARQL Endpoint via OAuth details how to generate the OAuth keys/tokens for use.

Hi @hwilliams,

I’m encountering an error when attempting to run the non-VAL procedure:

Error HTTP/1.1 404 File not found The requested URL was not found URI = ‘/oauth/’

Is it possible that I’m missing some package?

What are you testing against the Virtuoso open source or commercial build ? As the none VAL method only works with open source and not commercial as all OAuth functionality in the commercial builds are now in the VAL module which must be in place for OAuth to work.

Hi @hwilliams,

I was using the open version for this task …Also for the non commercial Virtuoso you must install Framework package.

In the commercial Version I have created via GUI this:

So, how can I invoke the endpoint SPARQL via CURL using token authentication ?

@hwilliams I dont know where to find parameters of the curl ex:

Example with curl and SPARQL-OAuth endpoint
  $ curl "

Also this endpoint is not present: oauth/sparql.vsp

Also where is set the relation between SPARQL USER → TOKEN
This scrip for Example:

import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

# Suppress only the InsecureRequestWarning from urllib3 needed for this example

# Step 1: Acquire an access token
token_url = "https://localhost/val/api/thirdparty_callback"
token_params = {
    "grant_type": "client_credentials",
    "client_id": "b45a32b21192d9389a7e827bb1f7286eae1e59a4",
    "client_secret": "673141f3bcb70adee1b34fc3d5e19da2",
    "token_endpoint_auth_method": "client_secret_jwt"

# Ignore SSL verification (Not recommended for production)
token_response =, data=token_params, verify=False)

# Uncomment the following line if providing the CA certificates
# token_response =, data=token_params, verify='/path/to/ca_certificates.pem')

# Uncomment the following line to ensure correct hostname
# token_response =, data=token_params, verify=True, headers={'Host': 'yourhostname'})

token_data = token_response.json()

if 'access_token' not in token_data:
    print("Error getting access token")

access_token = token_data['access_token']

# Step 2: Use the access token to make the SPARQL query
sparql_endpoint = "https://localhost/sparql"
sparql_query = "SELECT * WHERE {?s ?p ?o} LIMIT 10"  # Your SPARQL query goes here

headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/sparql-query"

# Ignore SSL verification (Not recommended for production)
sparql_response =, data=sparql_query, headers=headers, verify=False)

# Uncomment the following line if providing the CA certificates
# sparql_response =, data=sparql_query, headers=headers, verify='/path/to/ca_certificates.pem')

# Uncomment the following line to ensure correct hostname
# sparql_response =, data=sparql_query, headers=headers, verify=True, headers={'Host': 'yourhostname'})

if sparql_response.status_code == 200:
    print("SPARQL Query Results:")
    print("Error executing SPARQL query")

Is getting this error:

Error getting access token
    {'status': 'error', 'httpcode': '500', 'code': 'other_error', 'message': 'SP029: Not enough input parameters in the request'}


What is the version of the VAL VAD you have installed ? As in the OAuth Client Application Dialog you provide below the Application Key and Secret options I do not see an API Key option to enable the generate of displaying a bearer token for use in the OAuth connection.

I have this option with VAL 2.2.4_git109/ 2024-01-15 installed on my machine and can make a curl OAuth connection with a command of the form curl -H "Authorization: Bearer XXX" --request POST 'https://localhost/sparql/?' --data-urlencode 'query=INSERT INTO GRAPH <> {<4> <5> <6>}' where XXX is the API Key generated for the OAuth application ie

$ curl -H "Authorization: Bearer XXX" --request POST 'https://localhost/sparql/?' --data-urlencode 'query=INSERT INTO GRAPH  <> {<4> <5> <6>}'
<sparql xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <variable name="callret-0"/>
 <results distinct="false" ordered="true">
   <binding name="callret-0"><literal>Insert into &lt;;, 1 (or less) triples -- done</literal></binding>

Hi @hwilliams,

I have this version: 2.2.4_git78/ 2023-08-31 is possible to have your version, so I can make a test ?


Attached is the 2.2.4_git109/ 2024-01-15 VAL VAD I am using … (829.8 KB)

1 Like

Hi @hwilliams,

thanks is working fine :slight_smile: