When using the hosted OpenSanctions API, you must always provide an API key when you make requests.
When using the hosted OpenSanctions API, you must always provide an API key when you make requests.
To use the OpenSanctions API, you need an API key to identify yourself. Please visit the API product page or contact us to learn more.
We issue free API keys for public-interest work: journalism, civil-society advocacy, and academic research.
Once you have obtained an API key, you must include it with each request sent to the service. The key must be provided in the Authorization HTTP header:
Authorization: ApiKey xxxxxxxxxxxxxxxxxxxxxxxx
Here's a code snippet that demonstrates how you can include the API key in each request when using the Python requests library:
export OPENSANCTIONS_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxx" # replace with your own
python ↓
import os
import requests
API_URL = "https://api.opensanctions.org"
# Read an environment variable to get the API key:
API_KEY = os.environ.get("OPENSANCTIONS_API_KEY")
session = requests.Session()
session.headers['Authorization'] = f"ApiKey {API_KEY}"
# Run a match query:
query = {"schema": "Person", "properties": {"name": ["Vladimir Putin"]}}
request = {"queries": {"query": query}}
response = session.post(f"{API_URL}/match/default", json=request)
response.raise_for_status()
results = response.json().get("responses").get("query").get("results")
# Fetch an entity:
response = session.get(f"{API_URL}/entities/Q7747")
response.raise_for_status()
entity_data = response.json()