How to convert a DOI to a BibTeX file

DOI (Digital Object Identifier) are permanent identifiers for documents such as academic papers. A convenient way to quickly store a bibliography is to keep a list of DOI. Then there exist some web services to convert a DOI link to a bib file. For example, you can copy-paste your DOI on the website doi2bib.org. If you want to download the bib file from a script or a program, the website provides an API. Simply query the URL:

http://www.doi2bib.org/doi2bib?id=<DOI>

by replacing <DOI> by the corresponding DOI and the output will be a file in bib format.

For instance, for http://www.doi2bib.org/doi2bib?id=10.1007/978-1-4684-2001-2_9, the output should be:

@incollection{Karp_1972,
	doi = {10.1007/978-1-4684-2001-2_9},
	url = {https://doi.org/10.1007%2F978-1-4684-2001-2_9},
	year = 1972,
	publisher = {Springer {US}},
	pages = {85--103},
	author = {Richard M. Karp},
	title = {Reducibility among Combinatorial Problems},
	booktitle = {Complexity of Computer Computations}
}

The website doi.org also provides such an API. Assuming that the DOI is stored in the variable $doi, you can call the API from the Linux shell as follows:

wget --header="Accept: application/x-bibtex; charset=utf-8" -qO- "https://doi.org/$doi"

Or, if you prefer cURL:

curl -LH "Accept: application/x-bibtex; charset=utf-8" "https://doi.org/$doi"

I have written the following script to generate a bib file from one DOI or a list of DOIs.

#!/bin/sh
if test -t 0
then input="$@"
else input="$@ `cat`"
fi
for ref in $input
do
	doi=`echo $ref | sed -e "s/^\(\(https\?:\/\/\)\?\(dx.\)\?doi.org\/\|doi:\)//"`
	wget --header="Accept: application/x-bibtex; charset=utf-8" -qO- "https://doi.org/$doi"
	echo
done

Assume that you saved the script in the file doi2bib.sh, it can be called as follows:

./doi2bib.sh <DOI_list...>

Or, using a pipe, for example:

cat <file_with_DOIs> | ./doi2bib.sh

If you only need a citation in plain text format with the formatting style of your choice, the website citation.crosscite.org should fit your needs. The website doi.org also provides this service as an API:

wget --header="Accept: text/x-bibliography; style=$style" -qO- "https://doi.org/$doi"

where $doi is the DOI and $style is the formatting style (apa, elsevier-harvard, …).