wikidatawikidata-api

How to get formatter url from wikidata?


I'm trying to get all of the links that wikidata has stored for a person and display them. However most of the links use a formatter url, which means they have a code which tells them the main part of the url and then only the extension for that particular person is visible in the json file.

For the example of Douglas Adams: Under claims he has the following dictionary:

"P214": [
  {
    "mainsnak": {
      "snaktype": "value",
      "property": "P214",
      "hash": "20e5c69fbf37b8b0402a52948a04f481028e819c",
      "datavalue": {
        "value": "113230702",
        "type": "string"
      },
      "datatype": "external-id"
    },
    [...not important...]
]

So the link I'm searching for is https://viaf.org/viaf/113230702/, but only the number is really stored in the json. How do I get the whole link by using the property P214?

I've opened at least 30 tabs trying to look for a way to do this but I can't find anything, does anyone have an idea?

Thank you in advance.


Solution

  • The formatter URL property is P1630, so look up that property for any identifier you are interested in. Obviously you only need to do this once per type of identifier.

    Here's a fragment of the JSON returned for the VIAF identifier property:

    "P214": {
      "claims": {
        "P1630": [
          {
            "mainsnak": {
              "datavalue": {
                "value": "https://viaf.org/viaf/$1/",
                "type": "string"
              },
    

    To create the final URL, simply replace the $1 with the identifier string.