ihsn / metadataeditr

Metadata Editor R client
MIT License
1 stars 0 forks source link

collection_remove_projects doesn't work #1

Open thijsbenschop opened 1 week ago

thijsbenschop commented 1 week ago

Hi,

the function collection_remove_projects doesn't work. One reason is that the function argument collection_id in the R function is passed in the body as "collection_id", but should be "collections" according to the API documentation.

Also, the argument id_format cannot be passed through the R function. Therefore, I would propose to change the function as follows.

After these changes, the function returns a 200 success response, but the project is not removed from the collection.


{
  if (is.null(api_key)) {
    api_key = get_api_key()
  }
  options = list(collections = collection_id, id_format = id_format,
                 projects = projects)
  endpoint <- paste0("collections/remove_projects")
  if (is.null(api_base_url)) {
    url = get_api_url(endpoint = endpoint)
  }
  else {
    url = paste0(api_base_url, "/", endpoint)
  }
  httpResponse <- POST(url, add_headers(`X-API-KEY` = api_key),
                       body = options, content_type_json(), encode = "json",
                       accept_json(), verbose(get_verbose()))
  output = NULL
  if (httpResponse$status_code != 200) {
    warning(content(httpResponse, "text"))
  }
  output = list(status_code = httpResponse$status_code, response = fromJSON(content(httpResponse,
                                                                                    "text")), http_response = httpResponse)
  return(output)
}
mah0001 commented 1 week ago

The API endpoint has changed and now accepts an array for both collections and projects. The input/payload should look like this:

{
"collections": [13,12,15],
"id_format": "id",
"projects": [1,2,3,4]
}
thijsbenschop commented 1 week ago

Thanks Mehmood