Working With APIs In R

Screen Link:
https://app.dataquest.io/m/554/working-with-apis-in-r/5/extracting-api-responses-content

I don’t know what I am doing wrong. It doesn’t accept my answer.

My Code:

wb_api_json_get_df <- function(endpoint) {
  url <- modify_url("http://api.worldbank.org", path = endpoint)
  response <- GET(url)
  if ( http_error(response) ){
    print(status_code(response))
    stop("Something went wrong.", call. = FALSE)
  }
    if (http_type(response) != "application/json") {
    stop("API did not return json", call. = FALSE)
  }
    json_text<-content(response,as="text")
    json_text
  }
wb_indicator_json_text <- wb_api_json_get_df("v2/indicator?format=json")
2 Likes

I think the answer needs a refresh. My data shows 355 pages, but the answer has 351 pages.

2 Likes

I also think so. By the way there is another problem in the previous page. The instructions don’t match the answer. There is a missing instruction in that page.
https://app.dataquest.io/m/554/working-with-apis-in-r/4/tracking-errors

1 Like