Auto Downloading ODK submission using R

Dear Developer

How to auto download ODK submission using R
Regards

Hi @ChamisaShaps

ruODK is your best solution

3 Likes

Can you share documentation also?

Best,
@iamnarendrasingh

Hi,
The ruODK package is probably the easiest way but you can also do:

library(httr)
library(jsonlite)

url <- "https://private-anon-e51a308ee4-odkcentral.apiary-mock.com/v1/projects/projectId/forms/xmlFormId/Submissions"
r <- GET(url, authenticate("username", "password"))
stop_for_status(r)
text_content <- content(r, "text", encoding = "UTF-8")
json_content <- fromJSON(text_content,flatten = T)
df<-as.data.frame(json_content$value)

This will get the submissions, if you have repeats then add ?%24expand=* to the end of the url to get all the data i.e
url <- "https://private-anon-e51a308ee4-odkcentral.apiary-mock.com/v1/projects/projectId/forms/xmlFormId/Submissions?%24expand=*"

1 Like

@Stuart thank you very much. That is what i was looking for exactly. I am still getting error when tried to run your scripts. Can i get in touch with you

Hello,
This is Khine.
I would like to know if the "ruODK" or other R package works for encrypted data files.
Thanks. Khine

@Stuart i am facing the following challenge when i tried to use your scripts. What is the issue there
R_R

@ChamisaShaps wgat was the result from stop_for_status(r)? Have you changed the URL to your odk central server?

yes i have changed the url and inserted my credential. See the pic below again

ok so at the end of the url swap /submissons to .svc/Submissions

@Stuart how are you my boss. I failing to get the joy. I did what you instructed me to do but still failing

Hi, Looking at the error it seems to stem from your URL. I would surgest logining into central, opening the form selecting subbmissons and getting the url from the 'Analyze via OData' tab, copy that and it should solve the issue.

@Stuart finally we almost there . I have manged to run the code correct but when write view(df) am seeing the following results only while i am expecting to see all the columns (and rows) in the tool. What should i do. Do we need to converts data to data-frame or maybe there is a simple scripts for that
BD

Ah yes a little closer, if you add /Submissions to the URl you'll get the data before the repeat if you add /Submissions?%24expand=* then you'll get all the data

@Stuart am back again . Thanks for be with me . I am kindly lost a bit . Below is the script that working and with that url. I cannot see the word submission on my url . See the below . Where to adjust or change to allow the scripts to display the whole data set.

try https:\xxxxxxxx.svc/Submissions or https:\xxxxxxxx.svc/Submissions?%24expand=*

Hi @Khine!

Welcome to the forum. If you have a moment, introduce yourself in the welcome thread!

https://docs.ropensci.org/ruODK/reference/submission_export.html will work for encrypted forms. Central does not support access of individual encrypted records through OData or the Rest API.

1 Like

@Stuart finally we made it . Thank you very much and thank you very well

1 Like

No worries, happy to help

3 Likes