I’m not sure if this is the right place to ask this question but here it goes.
I’m trying to access a ckan portal (data.gov.mk) using ckanr. I’m just following the tutorial. Every time I try to package_show it returns an error:
Error: 400 - Bad Request (HTTP 400).
"\u041b\u043e\u0448\u043e \u0431\u0430\u0440\u0430\u045a\u0435 - JSON \u0433\u0440\u0435\u0448\u043a\u0430: Invalid request. Please use POST method for your request"
My R version is 3.5.3 (2019-03-11).
I’m not sure if there is anything else I should report. I don’t know if this is a ckanr issue or something is messed up with the ckan portal. Any insight would be helpful. Thanks.
library(ckanr)
ckanr_setup("https://data.gov.mk/")
res = package_search()
package_show(res$results[[1]]$id)
#> Error: 400 - Bad Request (HTTP 400).
#> "\u041b\u043e\u0448\u043e \u0431\u0430\u0440\u0430\u045a\u0435 - JSON \u0433\u0440\u0435\u0448\u043a\u0430: Invalid request. Please use POST method for your request"
Internally, package_show is doing a GET request.
A POST request does work
url = "https://data.gov.mk/api/3/action/package_show"
body = list(id = "30e85cc1-db68-44e6-a266-a263eb7f19a5")
res <- POST(url, body=body, encode="json", content_type_json())
we did have POST requests in the package for many fxns but changed them mostly to GET requests a while back because many CKAN instances blocked all POST requests https://github.com/ropensci/ckanr/issues/67
Not sure what to do here. We could allow the user to choose GET or POST http method
To be honest I am new at ckan/r and not entirely sure what is going on. Is it possible that they somehow misconfigured the ckan portal and it requires POST instead of GET?
Just to refresh this thread. It seems whatever was working with data.gov.mk doesn’t work anymore. The site no longer has https, and I suspect the api key is not being posted properly resulting in the same error as before.
If you reinstall remotes::install_github("ropensci/ckanr"), restart the R session, it should work now. you need to use http instead of https, and use http_method = "POST"
library(ckanr)
ckanr_setup("http://data.gov.mk/")
res = package_search()
package_show(res$results[[1]]$id, http_method = "POST")