|library(jsonlite) # if needing json format|
|cID<-"999" # client ID|
|secret<- "F00HaHa00G" # client secret|
|proj.slug<- "YourProjectSlug" # project slug|
|form.ref<- "YourFormRef" # form reference|
|branch.ref<- "YourFromRef+BranchExtension" # branch reference|
|res <- POST("https://five.epicollect.net/api/oauth/token",|
|body = list(grant_type = "client_credentials",|
|client_id = cID,|
|client_secret = secret))|
|token <- content(res)$access_token|
|# url.form<- paste("https://five.epicollect.net/api/export/entries/", proj.slug, "?map_index=0&form_ref=", form.ref, "&format=json", sep= "") ## if using json|
|url.form<- paste("https://five.epicollect.net/api/export/entries/", proj.slug, "?map_index=0&form_ref=", form.ref, "&format=csv&headers=true", sep= "")|
|res1<- GET(url.form, add_headers("Authorization" = paste("Bearer", token)))|
|# ct1<- fromJSON(rawToChar(content(res1))) ## if using json|
|# url.branch<- paste("https://five.epicollect.net/api/export/entries/", proj.slug, "?map_index=0&branch_ref=", branch.ref, "&format=json&per_page=1000", sep= "") ## if using json; pushing max number of records from default 50 to 1000|
|url.branch<- paste("https://five.epicollect.net/api/export/entries/", proj.slug, "?map_index=0&branch_ref=", branch.ref, "&format=csv&headers=true", sep= "")|
|res2<- GET(url.branch, add_headers("Authorization" = paste("Bearer", token)))|
|# ct2<- fromJSON(rawToChar(content(res2))) ## if using json|
This is very helpful - thanks for sharing! By chance, do you have code for retrieving original format images from an EpiCollect5 project in addition to form data? I tried the following, but got a '400' error:
I understand it may not be a priority to support these types of questions here, so please let me know if there is a better place to ask.
Look at your entries export to get the right filenames
Try to fork this fiddle and use your credentials. Do not forget to uncomment the auth part https://jsfiddle.net/mirko77/y45brprq/
I will try to give a full picture of what I am doing in R:
I then get the following server response:
As you can see, I think my file names are the correct format, and the
I hope that I have been clearer, and thank you for your time so far!
@schafnoir I'm doing the exact same thing as you (as in retrieving media from a private's project), and followed the same steps.
Hope it helps!
@StephPeriquet - I believe you are correct about the misplaced
@mirko77 - I wanted to let you know that in the code chunk above, the following no longer works due to the new
Ah ok, understood.
The code has not been written by myself ;)