Open jamesdunham opened 6 years ago
@jamesdunham thanks for such a thorough bug report and for being willing to submit a pull request! I'll defer to @leeper on what approach to take.
I think this may have changed at some point, or I never fully built-out the code. We definitely want to bring all of these arguments up into the function signature. I'd say all of the fields should be separate arguments with the non-required fields set by default to NULL
. Something like:
create_dataverse(
dataverse,
alias,
contacts,
affiliation = NULL,
description = NULL,
type = NULL
) {
bod <- list()
bod$name <- dataverse
bod$alias <- alias
bod$dataverseContacts <- setNames(as.list(contacts), rep("contactEmail", length(contacts)))
if (!is.null(affiliation)) {
bod$affiliation <- affiliation
}
if (!is.null(description)) {
bod$description <- description
}
if (!is.null(type)) {
bod$type <- match.arg(toUpper(type), c("DEPARTMENT", "JOURNAL", "LABORATORY", "ORGANIZATIONS_INSTITUTIONS", "RESEARCHERS", "RESEARCH_GROUP", "RESEARCH_PROJECTS", "TEACHING_COURSES", "UNCATEGORIZED"))
}
r <- httr::POST(u, httr::add_headers("X-Dataverse-key" = key), body = bod, ...)
}
If you want to submit that (or a modification thereof) as a PR along with updated documentation, please do. Otherwise I'll get to it as soon as I can.
I sat down to try the Dataverse API and
dataverse
today and ran into HTTP 400 (Bad Request) codes when callingcreate_dataverse()
. As often happens I figured out the solution while writing up the issue.problem
Without the
dataverse
argument, the expected behavior fromcreate_dataverse()
is "a top-level Dataverse is created." I probably don't have the permissions for that ondataverse.harvard.edu
, but this isn't relevant for demonstration:Code 400. Stepping through with
debug()
the request wasNote the empty body and content-type. For completeness, I do have the
admin
role for themedsl
dataverse atharvard.edu
, and get the same result withsolution
From the Dataverse API docs I see this behavior is actually expected. I'm sending an empty body, and minimally the API requires fields
name
,alias
, anddataverseContacts
.I can confirm this is the issue by sending a request with
httr
, using the example content from the docs as body content:That's a success and the new dataverse appears in the GUI unpublished. This result can be replicated with
create_dataverse()
using its dots argument, which is passed tohttr::POST()
.And that's also successful!
If
create_dataverse()
will always require body content, it might be worthwhile to movebody
into its signature as a new named argument and handle the encoding. Alternatively, the minimal metadata fields (name
,alias
,dataverseContacts
) could appear in the signature, since passing a named list is a little clunky. It looks something like this (.Names
elements added bydput
):Thoughts? If you're open to an update I can submit a PR.