Using R
An example of getting Epicollect5 data in R. Get the source code here.
1
library(httr)
2
library(jsonlite) # if needing json format
3
4
cID<-"999" # client ID
5
secret<- "F00HaHa00G" # client secret
6
proj.slug<- "YourProjectSlug" # project slug
7
form.ref<- "YourFormRef" # form reference
8
branch.ref<- "YourFromRef+BranchExtension" # branch reference
9
10
res <- POST("https://five.epicollect.net/api/oauth/token",
11
body = list(grant_type = "client_credentials",
12
client_id = cID,
13
client_secret = secret))
14
http_status(res)
15
token <- content(res)$access_token
16
17
# 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
18
url.form<- paste("https://five.epicollect.net/api/export/entries/", proj.slug, "?map_index=0&form_ref=", form.ref, "&format=csv&headers=true", sep= "")
19
20
res1<- GET(url.form, add_headers("Authorization" = paste("Bearer", token)))
21
http_status(res1)
22
# ct1<- fromJSON(rawToChar(content(res1))) ## if using json
23
ct1<- read.csv(res1$url)
24
str(ct1)
25
26
# url.branch<- paste("https://five.epicollect.net/api/export/entries/", proj.slug, "?map_index=0&branch_ref=", branch.ref, "&format=json&per_page=1000000", sep= "") ## if using json; pushing max number of records from default 50 to 10^6
27
url.branch<- paste("https://five.epicollect.net/api/export/entries/", proj.slug, "?map_index=0&branch_ref=", branch.ref, "&format=csv&headers=true", sep= "")
28
29
res2<- GET(url.branch, add_headers("Authorization" = paste("Bearer", token)))
30
http_status(res2)
31
ct2<- read.csv(res2$url)
32
# ct2<- fromJSON(rawToChar(content(res2))) ## if using json
33
str(ct2)
Copied!
Last modified 2yr ago
Copy link