I am trying to query the Cameo database.
If I use the URL https://cameo.mfa.org/api.php?action=query&pageids=17051&prop=extracts&format=json, then I get, online, a valid output.
However, if I use:
library(httr)
library(jsonlite)
base_url <- "https://cameo.mfa.org/api.php"
query_param <- list(action = "query",
pageids = "17051",
format = "json",
prop = "extracts"
)
parsed_content <- httr::GET(base_url, query_param)
jsonlite::fromJSON(content(parsed_content, as = "text", encoding = "UTF-8"))
Then jsonlite
fails because the output is in html format and not json.
Do you have any advice on this?
2
Answers
A bit different approach:
Created on 2023-07-03 with reprex v2.0.2
The second argument to
httr::GET
isconfig=
, which is not where you should be assigningquery_param
. Instead name it asquery=query_param
.