0

The MediaWiki API is able to find ID for an item with the request URL: /w/api.php?action=query&format=json&prop=pageprops&titles=skype&formatversion=2&ppprop=wikibase_item

The result is:

{
    "batchcomplete": true,
    "query": {
        "normalized": [
            {
                "fromencoded": false,
                "from": "skype",
                "to": "Skype"
            }
        ],
        "pages": [
            {
                "pageid": 424589,
                "ns": 0,
                "title": "Skype",
                "pageprops": {
                    "wikibase_item": "Q40984"
                }
            }
        ]
    }
}

However, it does not work well when querying about a property, e.g., developer P178. The result is Q409857 rather than the desired P178:

{
    "batchcomplete": true,
    "query": {
        "normalized": [
            {
                "fromencoded": false,
                "from": "developer",
                "to": "Developer"
            }
        ],
        "pages": [
            {
                "pageid": 179684,
                "ns": 0,
                "title": "Developer",
                "pageprops": {
                    "wikibase_item": "Q409857"
                }
            }
        ]
    }
}

Is there any way to get the ID for an entity which could be an item, a property or even a lexeme?

recnac
  • 3,744
  • 6
  • 24
  • 46
Xue Li
  • 1

1 Answers1

1

You could use on Wikidata the search API.

For example, to find properties with the name "developer" inside, use https://www.wikidata.org/w/api.php?action=query&list=search&srsearch=developer&srnamespace=120

120 is the property namespace. To find a lexeme, use srnamespace=146.

Note, this API guesses your language and adapts the results correspondingly. If you don't live in an English speaking country, the above example may thus fail.

Pascalco
  • 2,481
  • 2
  • 15
  • 31