Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad request 400 with passing metadata - zenodo license? #101

Open
collinschwantes opened this issue Aug 21, 2024 · 1 comment
Open

bad request 400 with passing metadata - zenodo license? #101

collinschwantes opened this issue Aug 21, 2024 · 1 comment

Comments

@collinschwantes
Copy link

collinschwantes commented Aug 21, 2024

License validation for zenodo deposits may be too permissive. In the example below, the metadata passes validation when creating a new client but fails with a 400 error when running deposit_new.

The Zenodo API describes a list of approved licenses. https://developers.zenodo.org/#licenses

library(deposits)

dotenv::load_dot_env()
iris_metadata

metadata <- list (
  title = "New Title",
  description = "This is the abstract",
  creator = list (list (name = "A. Person", orcid = "https://orcid.org/0000-0002-0872-9950"), list (name = "B. Person", orcid = "https://orcid.org/0000-0002-9882-941X")),
  subject = list(name = "hello",name = "world"),
  format = "dataset",
  created = "2024-08-01",
  license = "cc-by-9999"
)

cli_test <- depositsClient$new (
  service = "zenodo",
  sandbox = TRUE,
  metadata = metadata
)


cli_test$deposit_new()

Using an approved license the deposit_new method works.

library(deposits)

dotenv::load_dot_env()
iris_metadata

metadata <- list (
  title = "New Title",
  description = "This is the abstract",
  creator = list (list (name = "A. Person", orcid = "https://orcid.org/0000-0002-0872-9950"), list (name = "B. Person", orcid = "https://orcid.org/0000-0002-9882-941X")),
  subject = list(name = "hello",name = "world"),
  format = "dataset",
  created = "2024-08-01",
  license = "cc-by-nc-sa-4.0"
)

cli_test <- depositsClient$new (
  service = "zenodo",
  sandbox = TRUE,
  metadata = metadata
)


cli_test$deposit_new()

Quick and dirty function for querying the license api

#' Query Zenodo Licenses
#'
#' @param q Character. Text based query 
#' @param page Numeric. Page number of query results
#' @param size Numeric. Number of results to return per page. There are 444 different
#'  licenses in Zenodo as of August 2024
#' @param .multi Character. See `httr2::req_url_query` 
#'
#' @return Response object from `httr2::req_perform`
#' @export
#'
#' @examples
#' 
#' # look for creative commons licenses
#' response <- query_zenodo_licenses(q = "creative commons",size = 444)
#' 
#' # get the json body of the response
#' license_list <- response |> httr::2resp_body_json()
#' 
#' # get just the ids from the response
#' license_list$hits$hits |>
#'   purrr::map(\(x) x$id)
#' 
query_zenodo_licenses <- function( q=NA, page =NA, size =NA,.multi = "explode"){
  base_url <- "https://zenodo.org/api/licenses"
  
  req <- httr2::request(base_url)
  
  params<- list(q = q,
                page = page,
                size = size)
  
  keep_params <- !is.na(params)
  
  print(params[keep_params])
  
  req <- req |>
    req_url_query(!!!params[keep_params])
  
  response <- req |> req_perform()
  return(response)
}
@collinschwantes
Copy link
Author

Looks like there is already a list of accepted licenses from ~6 months ago - https://github.com/ropenscilabs/deposits/blob/main/inst/extdata/zenodo/zenodo_licenses.csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant