APIs / Search engines / Wikidata

1 credit per call2 endpoints6 datapoints

Wikidata API

Wikidata API to search items and properties by label and get an item's claims with resolved labels, aliases and Wikipedia sitelinks as JSON.

Wikidata
GET/v1/wikidata/entity?id=Q42
{
  "success": true,
  "data": {
    "id": "Q42",
    "type": "item",
    "language": "en",
    "label": "Douglas Adams",
    "description": "British science fiction writer and humorist (1952–2001)",
    "aliases": [
      "Douglas Noël Adams",
      "Douglas Noel Adams",
      "Douglas N. Adams"
    ],
    "claim_count": 355,
    "claims": [
      {
        "property": "P31",
        "property_label": "instance of",
        "datatype": "wikibase-item",
        "value": "Q5",
        "value_label": "human",
        "rank": "normal"
      },
      {
        "property": "P21",
        "property_label": "sex or gender",
        "datatype": "wikibase-item",
        "value": "Q6581097",
        "value_label": "male",
        "rank": "normal"
      },
      {
        "property": "P106",
        "property_label": "occupation",
        "datatype": "wikibase-item",
        "value": "Q214917",
        "value_label": "playwright",
        "rank": "normal"
      }
    ],
    "sitelinks": [
      {
        "site": "abstractwiki",
        "title": "Q42",
        "url": "https://abstract.wikipedia.org/wiki/Q42"
      },
      {
        "site": "afwiki",
        "title": "Douglas Adams",
        "url": "https://af.wikipedia.org/wiki/Douglas_Adams"
      },
      {
        "site": "arwiki",
        "title": "دوغلاس آدمز",
        "url": "https://ar.wikipedia.org/wiki/%D8%AF%D9%88%D8%BA%D9%84%D8%A7%D8%B3_%D8%A2%D8%AF%D9%85%D8%B2"
      }
    ],
    "url": "https://www.wikidata.org/wiki/Q42"
  },
  "meta": {
    "request_id": "req_d8c542b624184b2394ebee0425537770",
    "credits_charged": 1,
    "credits_remaining": 481
  }
}
200 OKJSONX-Credits-Used: 1
Recorded from our API and shortened.

Sample data

What one call returns

A recorded run of entity: the fields and shapes you will get, shortened to 3 items.

#propertystringproperty_labelstringdatatypestringvaluestringvalue_labelstringrankstring
1P31instance ofwikibase-itemQ5humannormal
2P21sex or genderwikibase-itemQ6581097malenormal
3P106occupationwikibase-itemQ214917playwrightnormal

Recorded from our API · 3 items shown · 6 datapoints per itemGET /v1/wikidata/entity?id=Q42

6 datapoints

Identity

  • datatypestring

Other

  • propertystring
  • property_labelstring
  • valuestring
  • value_labelstring
  • rankstring

Playground

Run this API

cURLshell
curl "https://api.perceptlayer.com/v1/wikidata/entity?id=Q42" \
  -H "X-API-Key: $API_KEY"

Wikidata · 2 endpoints

Endpoints

Every endpoint takes the same key. Open one for its parameters, the fields it returns and an example request.

EndpointRequired parametersReturnsCost
GET/v1/wikidata/entity
id+2 optional
idtypelanguagelabeldescriptionaliases+4 more
1 credit
GET/v1/wikidata/entity-search
query+4 optional
idlabeldescriptionmatchurl
1 credit

Overview

About the Wikidata API

What you can get

The Wikidata API returns structured data from Wikidata as JSON through 2 endpoints.

  • Entity search: entity-search takes a query, matched against labels and aliases, with language (such as en or fr; default en), type (item for Q ids or property for P ids; default item), limit (1 to 50, default 10) and page.
  • Entity: entity takes an id, such as Q42 (an item) or P31 (a property), with language for labels, descriptions and aliases, and claims_limit (1 to 500, default 50).

The recorded entity-search for "douglas adams" returns page, has_more and items, each with id, label, description, match (the type, language and text it matched on) and a url. The recorded entity call for Q42 returns id, type, language, label (Douglas Adams), description ("British science fiction writer and humorist (1952–2001)"), aliases (such as Douglas Noël Adams), claim_count (355 in that recording), claims and sitelinks. Each claim is flattened to property and property_label, datatype, value and value_label, and rank: P31 "instance of" Q5 "human", for example. Labels are resolved for the first 50 ids. Each sitelink has a site (such as afwiki), the article title and its url.

Wikidata's structured data (items and properties) is CC0, so no attribution is required. Wikipedia article text is under a different licence (CC BY-SA) and is never fetched or returned: sitelinks carry only the article title and URL.

How a call works

Search, then look up: GET /v1/wikidata/entity-search?query=douglas+adams with your key in the X-API-Key header returns each match's id; entity takes it, for example GET /v1/wikidata/entity?id=Q42&claims_limit=100. Check has_more before asking for the next page. Answers come from a cache for up to 24 hours. Every successful call costs 1 credit; failed calls cost nothing.

Search enginesJSONRESTMCP

More search engines APIs

Use cases

Let an agent resolve a name to a Wikidata Q id before answering questions about it

Use the Wikidata API to let an agent resolve a name to a Wikidata Q id before answering questions about it

Ground an LLM answer in an entity's claims, with property and value labels already resolved

Use the Wikidata API to ground an LLM answer in an entity's claims, with property and value labels already resolved

Link records in a dataset to Wikidata ids for entity resolution

Use the Wikidata API to link records in a dataset to Wikidata ids for entity resolution

Find an entity's Wikipedia article titles and URLs in each language from `sitelinks`

Use the Wikidata API to find an entity's Wikipedia article titles and URLs in each language from `sitelinks`

FAQ

Questions

Is this the official Wikidata API?

No. Perceptlayer is an independent service and is not affiliated with or endorsed by Wikidata or the Wikimedia Foundation. Wikidata's Action API is free to call directly; Wikimedia asks callers to identify themselves in a User-Agent and limits unidentified clients. This API calls it on your behalf and adds one key for every source on Perceptlayer, claims flattened with their labels in one response shape, a cache of up to 24 hours, and no charge for failed calls.

Do I need to credit Wikidata?

No. Wikidata's structured data is CC0, dedicated to the public domain. Wikipedia article text is CC BY-SA, which is why this API returns only article titles and URLs, never the text.

Why do some claims have no `value_label`?

Labels are resolved for the first 50 ids in a response: properties, item values and units, in claim order. Claims beyond that come without labels, and values that aren't items (such as dates and strings) have no label to resolve. Quantities add `unit_id` and `unit_label`.

What does `match` tell me in a search result?

Whether the query matched the entity's label or an alias, in which language, and the text it matched. In the recording, the first result matched on its English `label`.

Should I build a Wikidata scraper instead?

You can, but a Wikidata scraper is code you maintain: page changes break it, requests get blocked, and Wikidata's terms govern how you collect data. The Wikidata API gives you 2 endpoints of named JSON fields for 1 credit per successful call, and failed calls cost nothing. A scraper makes sense only for data these endpoints don't return, so check the response in the playground on this page first.

Try the Wikidata API with 100 free credits

No credit card. Failed calls are never billed.