Code
# These are the libraries that we'll need to run this workbook
library(httr2)
library(dplyr)
library(stringr)
library(purrr)
library(DT)
January 12, 2024
This document is focused on showing and letting you download the result of some Crossref REST API requests. You will see different outputs in tables that you can explore and filter.
If you want to inspect the code behind any request you can click on any of the “Code” buttons to display specific code chunks.
Here we’ll be using the httr2 R package1 If want to know more details about how to build these API requests, you can check any of our introductory documents.
It’s always convenient to remember this section. As per our documentation2:
There are three ways to access the REST API. In increasing levels of reliability and predictability. They are:
- Anonymously (aka Public)
- With self identification (aka Polite)
- With authentication (aka Plus)
…you can also self-identify by including contact information in your requests. The service is still open and free, but this way we can quickly get in touch with you if your scripts are causing problems. And in turn for providing this contact information, we redirect these requests to a specific “Polite” pool of servers. These servers are generally more reliable because we are more easily able to protect them from misbehaving scripts.
In R, you can add your email as a system variable using the command Sys.setenv(crossref_email = "your.name@yourorganization.org")
You can explore our list of funding organizations available with a Croosref ID
Click or copy and paste the following API request URL to your browser search bar:
https://api.crossref.org/funders/?mailto=yourname@organization.com
test <- fund_list |>
resp_body_json()
#test$message$`total-results`
test$message$items |>
map_dfr(
\(x) {
tibble(
"Crossref ID" = x |> pluck('id'),
"Name" = x |> pluck('name'),
"Location" = x |> pluck('location')
)
}
) |>
datatable(rownames = FALSE,
extensions = 'Buttons',
options = list(
dom = 'frtipB',
buttons = c('copy', 'csv', 'excel', 'pdf')))
You can use this table to find your funder ID, and then retrieve all the works that list this id as their funding organization
Click or copy and paste the following API request URL to your browser search bar:
https://api.crossref.org/works/?mailto=yourname@organization.com&filter=funder:10.13039/100008539
funded_list$message$items |>
map_dfr(
\(x) {
tibble(
"DOI" = x |> pluck('DOI'),
"Published online" = x |> pluck('published'),
"Is referenced by" = x |> pluck('is-referenced-by-count')
)
}
) |>
datatable(rownames = FALSE,
extensions = 'Buttons',
options = list(
dom = 'frtipB',
buttons = c('copy', 'csv', 'excel', 'pdf')))
Besides adding funding information, works can explicitly include a relationship statement, which would be the ideal scenario.
Click or copy and paste the following API request URL to your browser search bar:
https://api.crossref.org/works?filter=relation.type:is-financed-by&mailto=yourname@organization.com
funded_by_list$message$items |>
map_dfr(
\(x) {
tibble(
"DOI" = x |> pluck('DOI'),
"Publisher" = x |> pluck('publisher'),
"Funded by" = x |> pluck('relation') |> pluck("is-financed-by") |> map_chr(\(y){("test"=y |> pluck("id"))}) |> str_flatten_comma()
)
}
) |>
datatable(rownames = FALSE,
extensions = 'Buttons',
options = list(
dom = 'frtipB',
buttons = c('copy', 'csv', 'excel', 'pdf')))
Perhaps we are more interested in grant-specific information. For instance, you can retrieve for example the list of registered grants:
Click or copy and paste the following API request URL to your browser search bar:
Crossref API for funding data by Luis Montilla is licensed under CC BY 4.0