suppressPackageStartupMessages(library(tidyverse))
library(jsonlite)
library(httr)
# my_authtoken <- "xxxxxxxxxxxxxxxxxxx"
GET request
data1 <- fromJSON(paste0("https://data.eppo.int/api/rest/1.0/taxon/BEMITA/names?authtoken=", my_authtoken))
data1 %>%
str %>%
print
## 'data.frame': 38 obs. of 6 variables:
## $ nameid : int 7224 211279 211280 280710 7220 7221 7222 180181 273619 7241 ...
## $ isolang : chr "la" "de" "de" "de" ...
## $ isocountry: chr NA NA NA NA ...
## $ fullname : chr "Bemisia tabaci" "Baumwollmottenschildlaus" "Tabakmottenschildlaus" "weiße Fliege" ...
## $ preferred : int 1 0 0 0 0 0 0 0 0 0 ...
## $ author : chr "(Gennadius)" NA NA NA ...
## NULL
POST request
# I can execute test code from the SO post:
# https://stackoverflow.com/questions/26693842/how-do-i-post-a-json-formatted-request-to-get-json-data-from-a-url-in-r-into-the
# but I can not figure out how to apply the functions in my case
req <- POST("http://api.scb.se/OV0104/v1/doris/sv/ssd/START/PR/PR0101/PR0101A/KPIFastM2",
body = '{ "query": [], "response": { "format": "json" } }')
stop_for_status(req)
json <- content(req, "text")
json %>%
fromJSON %>%
str(1) %>%
print
## List of 4
## $ columns :'data.frame': 2 obs. of 3 variables:
## $ comments: list()
## $ data :'data.frame': 183 obs. of 2 variables:
## $ metadata:'data.frame': 1 obs. of 4 variables:
## NULL