onaio / ona.R

Ona Plugin for R
https://github.com/onaio/ona.R
5 stars 10 forks source link

Unable to import data into R #29

Closed samwata closed 11 months ago

samwata commented 2 years ago

I am getting the attached error when I try to import data into R

Steps to reproduce the error

#Download dev tools library
install.packages("devtools", dependencies = TRUE)

#Check if dev tools library has been installed
library(devtools)
install_github('onaio/ona.R')

#Check if ona library has been installed
library(ona)

# Download the dataset
good_eats <- onaDownload("good_eats", "mberg","mberg")

image

good_eats <- onaDownload("good_eats", "mberg","mberg") Error in function (type, msg, asError = TRUE) : error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

George-Kamau commented 1 year ago

From the error we are getting when trying to connect to ONA, it seems there is a connection error when trying to reach the ONA Data API, specifically, something about the TLS version. I found some information about this error here.

You can find the R script being used to call the API here. Specifically, the endpoint being used by the onaDownload function looks like this: https://api.ona.io/ <account>/forms/<formName>/<form.json> or <data.csv>

eochieng-lab commented 11 months ago

I'm going to close this issue for now since its been open for over a year and there is no work that is currently being put into addressing it.

mbaldassaro commented 11 months ago

A workaround:

library(httr)
library(jsonlite)

api_token <- "your api token"
form_id <- "your form id"

api_url <- paste0("https://api.ona.io/api/v1/data/", form_id)

headers <- c(
  Authorization = paste("Token", api_token)
)

response <- GET(api_url, add_headers(.headers=headers))

if (http_status(response)$category == "Success") {
  response_data <- fromJSON(content(response, "text"))
} else {
  cat("API request failed with status:", http_status(response)$reason, "\n")
}