Citoid/API

From MediaWiki.org
Jump to: navigation, search

This document describes how to interact with the native API for the citoid service. However, this API is deprecated in favour of https://en.wikipedia.org/api/rest_v1/#!/Citation/getCitation, which uses a different request format. Only the response section in this documentation is relevant for restbase requests.

For developers, you will find this endpoint at http://localhost:1970/api by default.

The API endpoint accepts GET data. In the GET request, three arguments are accepted: search and format.

Requests[edit]

Arguments[edit]

  • search currently takes URLs, DOIs, PMCIDs, and PMIDs. If the DOI, PMCID, or PMID is unresolvable, you will get back a 404 response and a JSON error message.
  • format takes 'mediawiki', 'zotero' , 'bibtex' , and 'mediawiki-basefields'. 'zotero'is the format used by the zotero service, and is the format that citoid uses internally. 'mediawiki' is the targeted format, and is designed for use by TemplateData maps found in citation templates. You may find, depending on your use case, for the 'zotero' format to be richer. The format 'mediawiki-basefields' is largely the same as 'mediawiki' , but will return the base fields for the data in instead of the mapped fields. For example, it will return publicationTitle instead of bookTitle or websiteTitle.

Headers[edit]

To try to request a website in a particular language, you can set the accept-language header in your request, and citoid will attempt to retrieve the website in that language.

This will not work for any request results coming from Zotero since Zotero does not have this feature. It also may not work if the website does not use the accept-request header in order to determine what language to return the sites in.

Response[edit]

Successful response in mediawiki format[edit]

A successful (200 ok) citoid response for the 'mediawiki' format consists of an Array of citation Objects, [{}] in the body. At present, there is guaranteed to be only one citation Object in the Array.

Field names[edit]

The 'mediawiki' format uses the same itemTypes and parameter names as the 'zotero' format, with three additional parameters: PMID, PMCID, and source. A nearly complete list of all itemTypes possible and each itemType's respective parameters are available from Zotero here.

Parameters for which there is no value will not be included in the response. There are three required parameters that will always be returned: itemType , url and title.

Parameters which are written in parentheses on the Zotero type map are called basefields. By default, you will get the first parameter name. You can request the basefield instead as a query parameter in the request.

Field values[edit]

The values for most fields are Strings. The value of the fields issn , isbn, PMID , PMCID and source are Arrays of Strings. The value of any creator type (i.e. author, editor, programmer, etc.) is an Arrays of Arrays, i.e. [['firstname'],['lastname']].

The possible String values in the Array source are: 'citoid', 'Crossref', 'PubMed', and 'Zotero'. This indicates where the metadata was retrieved from.

Unsuccessful response[edit]

Alongside regular errors (400 Bad Request), we have a custom 520 response that returns a citation object even if no data is able to be retrieved.

Examples[edit]

Making a request to API/ endpoint (GET)[edit]

In a browser[edit]

http://localhost:1970/api?search=10.1038%2Fng.590&format=mediawiki

In a JavaScript userscript[edit]

$.ajax( {
	beforeSend: function (request) {
		request.setRequestHeader('Content-Type', 'application/json');
		request.setRequestHeader('accept-language', 'en'); // Use this header to request the resource in the particular language, i.e. 'en', 'de'

	},
	url: ' https://citoid.wikimedia.org/api'
	type: 'GET',
	data: { 
		search: encodeURIComponent('10.1038/ng.590'),
		format: 'mwDeprecated'
	},
	dataType: 'json',
	success: function ( citationArray ) {
		doSomething( citationArray );
	},
	error: function ( request, textStatus, errorThrown) {
		alert( 'Status:'  + textStatus +  'Error: ' + errorThrown );
	}
} );

Sample output[edit]

Below are sample outputs of two of the export formats. The primary difference is in how creators/authors/editors are handled. In zotero, these are all in the creator object, and in mediawiki they are in a list of [firstname, lastname] lists keyed by the creatorType value. In only mediawiki, ISBN and ISSN are lists.

zotero[edit]

[ { "DOI" : "10.1371/journal.pcbi.1002947",
      "ISSN" : "1553-7358",
      "abstractNote" : "Viral phylodynamics is defined as...",
      "creators" : [ { "creatorType" : "author",
            "firstName" : "Erik M.",
            "lastName" : "Volz"
          },
          { "creatorType" : "author",
            "firstName" : "Katia",
            "lastName" : "Koelle"
          },
          { "creatorType" : "author",
            "firstName" : "Trevor",
            "lastName" : "Bedford"
          }
        ],
      "date" : "2013",
      "extra" : "PMID: 23555203 \nPMCID: PMC3605911",
      "issue" : "3",
      "itemKey" : "XK9ACBRA",
      "itemType" : "journalArticle",
      "itemVersion" : 0,
      "journalAbbreviation" : "PLoS Comput. Biol.",
      "language" : "eng",
      "libraryCatalog" : "NCBI PubMed",
      "pages" : "e1002947",
      "publicationTitle" : "PLoS computational biology",
      "tags" : [ { "tag" : "Adaptation, Biological",
            "type" : 1
          },
          { "tag" : "Computational Biology",
            "type" : 1
          }
        ],
      "title" : "Viral phylodynamics",
      "volume" : "9"
    } ]

mediawiki[edit]

[ { "DOI" : "10.1371/journal.pcbi.1002947",
    "ISSN" : ["1553-7358"],
    "PMID" : "23555203",
    "abstractNote" : "Viral phylodynamics is defined as...",
    "author" : [ [ "Erik M.",
          "Volz"
        ],
        [ "Katia",
          "Koelle"
        ],
        [ "Trevor",
          "Bedford"
        ]
      ],
    "date" : "2013",
    "extra" : "PMID: 23555203 \nPMCID: PMC3605911",
    "issue" : "3",
    "itemKey" : "CTVVXDEA",
    "itemType" : "journalArticle",
    "itemVersion" : 0,
    "journalAbbreviation" : "PLoS Comput. Biol.",
    "language" : "en",
    "libraryCatalog" : "NCBI PubMed",
    "pages" : "e1002947",
    "publicationTitle" : "PLoS computational biology",
    "tags" : [ { "tag" : "Adaptation, Biological",
          "type" : 1
        },
        { "tag" : "Computational Biology",
          "type" : 1
        }
      ],
    "title" : "Viral phylodynamics",
    "url" : "http://www.ncbi.nlm.nih.gov/pubmed/23555203",
    "volume" : "9",
    "source" : ["Zotero"]
  } ]