> **For coding agents and LLMs:** This is one Social Fetch marketing page (markdown export). For API orientation start with [`/llms.txt`](https://www.socialfetch.dev/llms.txt); for auth and crawl rules use [`/agents.txt`](https://www.socialfetch.dev/agents.txt); for every operation use [`/llms-endpoints.txt`](https://www.socialfetch.dev/llms-endpoints.txt).

## This page

- **On-site (HTML):** <https://www.socialfetch.dev/platforms/wikipedia/wikidata-query>
- **Markdown (.mdx) URL:** <https://www.socialfetch.dev/platforms/wikipedia/wikidata-query.mdx>

---

# Wikidata SPARQL API

Read-only SPARQL queries with typed bindings and a row count.

`GET /v1/wikipedia/wikidata/query?sparql=SELECT%20...` runs a read-only SPARQL query and returns `data.head.vars`, `data.bindings`, `data.boolean` and `data.rowCount`. `bindings` is an array of rows, and each binding value has `type`, `value` and, where relevant, `datatype` and `lang`.

`format` only accepts `json`. `sparql` is limited to 10,000 characters. The query must be read-only: `INSERT`, `DELETE`, `LOAD`, `CLEAR`, `DROP`, `CREATE`, `ADD`, `MOVE`, `COPY` and `WITH` are refused. A SELECT returns rows in `bindings`; an ASK answer returns the result in `boolean` and leaves `bindings` empty. `empty` is true when a SELECT matched no rows.

`rowCount` always matches the length of `bindings`. The result is capped at 2,000,000 bytes, so add a `LIMIT` or narrow the query when it grows. Wikidata applies its own timeout to long queries, so keep queries narrow and select only the variables you need.

## Request

- **Endpoint:** `GET /v1/wikipedia/wikidata/query`
- **Credits:** 1 credit
Failed requests are free
- **Input:** by SPARQL query
- **Full reference:** [docs](https://www.socialfetch.dev/docs/api/v1/wikipedia/wikidata/query/get)
- **Platform page:** [/platforms/wikipedia](https://www.socialfetch.dev/platforms/wikipedia)

## FAQ

### Can I write to Wikidata with this route?

No. Only read-only queries are accepted. Statements that change data, such as INSERT, DELETE, LOAD, CLEAR, DROP, CREATE, ADD, MOVE, COPY and WITH, are refused before the query runs.

### How do I read an ASK answer?

An ASK query fills data.boolean with true or false. bindings is empty for an ASK answer, and head.vars lists the variables the service reports.

### Why is rowCount useful?

rowCount is the number of rows in bindings, so you can check that a query returned what you expected without counting the array. A SELECT with no matches is found with rowCount 0 and empty true.

### How many credits does a SPARQL query cost?

Pricing is documented on the operation in the API registry (shown on this page). Confirm on every response with meta.creditsCharged: that field is the billing source of truth.
