Crossref API for funding data

Published

January 12, 2024

How to use this workbook

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.

Code
# These are the libraries that we'll need to run this workbook
library(httr2)
library(dplyr)
library(stringr)
library(purrr)
library(DT)
Code
base_url <- "https://api.crossref.org/"
endpoint <- "/funders"

Setup polite requests

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")

Code
Sys.setenv(crossref_email = "your.name@yourorganization.org")

List of organizations

You can explore our list of funding organizations available with a Croosref ID

Code
fund_list <- request(base_url) |> 
  req_url_path_append(endpoint) |> 
  req_url_query() |> 
  req_perform()

Click or copy and paste the following API request URL to your browser search bar:

https://api.crossref.org/funders/?mailto=yourname@organization.com

Code
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')))

Works that list a specific funder

You can use this table to find your funder ID, and then retrieve all the works that list this id as their funding organization

Code
funded_works_url <- "https://api.crossref.org/works"
#endpoint <- "/funders"
funded_list <- request(funded_works_url) |> 
  #req_url_path_append(endpoint) |> 
  req_url_query(filter = "funder:100000014") |> 
  req_perform() |> 
  resp_body_json()

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

Code
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')))

Works that list a specific funder relationship

Besides adding funding information, works can explicitly include a relationship statement, which would be the ideal scenario.

Code
funded_by <- "https://api.crossref.org/works"
funded_by_list <- request(funded_by) |> 
  #req_url_path_append(endpoint) |> 
  req_url_query(filter = "relation.type:is-financed-by") |> 
  req_perform() |> 
  resp_body_json()

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

Code
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')))

List of grants

Perhaps we are more interested in grant-specific information. For instance, you can retrieve for example the list of registered grants:

Code
grants_url <- "https://api.crossref.org/works"
#endpoint <- "/funders"
grants_list <- request(grants_url) |> 
  #req_url_path_append(endpoint) |> 
  req_url_query(filter = "type:grant") |> 
  req_perform() |> 
  resp_body_json()

Click or copy and paste the following API request URL to your browser search bar:

https://api.crossref.org/works/?filter=type:grant&mailto=lmontilla@crossref.org&select=DOI,member,publisher

Code
grants_list$message$items |> 
  map_dfr(
    \(x) {
      tibble(
        "DOI" = x |> pluck('DOI'),
        "Publisher" = x |> pluck('publisher'),
        "Member" = x |> pluck('member')
      )
    }
  ) |> 
  datatable(rownames = FALSE,
            extensions = 'Buttons', 
            options = list(
              dom = 'frtipB',
              buttons = c('copy', 'csv', 'excel', 'pdf')))

Other resources

References

1. Wickham, H. (2024). httr2: Perform HTTP requests and process the responses. https://httr2.r-lib.org
2. Polischuk, P. (2021). Tips for using the crossref REST API. https://www.crossref.org/documentation/retrieve-metadata/rest-api/tips-for-using-the-crossref-rest-api/

Licence

Crossref API for funding data by Luis Montilla is licensed under CC BY 4.0