Getting survey data from Qualtrics API using R | XM Community
Skip to main content

I am trying to download survey data (around 5000 responses) from Qualtrics using the API in R. I am using the `qualtRics` package.

 

Here’s my code:

 

library("qualtRics")


qualtrics_api_credentials(api_key = "abcxyz", #A valid token key
base_url = "dc1.qualtrics.com",
install = TRUE)



surveys <- all_surveys()

glimpse(surveys) #this gives me a list of surveys from my qualtrics account.


ema_survey <- fetch_survey(surveyID = surveys$ids6])
glimpse(ema_survey)

> ema_survey <- fetch_survey(surveyID = surveys$ids6], verbose = TRUE)
|=======================================================================================================| 100%

── Column specification ─────────────────────────────────────────────────────────────────────────────────────────
cols(
StartDate = col_character(),
EndDate = col_character(),
Status = col_character(),
IPAddress = col_character(),
Progress = col_character(),
`Duration (in seconds)` = col_character(),
Finished = col_character(),
RecordedDate = col_character(),
ResponseId = col_character(),
RecipientLastName = col_character(),
RecipientFirstName = col_character(),
RecipientEmail = col_character(),
ExternalReference = col_character(),
LocationLatitude = col_character(),
LocationLongitude = col_character(),
DistributionChannel = col_character(),
UserLanguage = col_character(),
Q1_1 = col_character()
)

> ema_survey
# A tibble: 0 × 18
# ℹ 18 variables: StartDate <chr>, EndDate <chr>, Status <chr>, IPAddress <chr>, Progress <chr>,
# Duration (in seconds) <chr>, Finished <chr>, RecordedDate <chr>, ResponseId <chr>, RecipientLastName <chr>,
# RecipientFirstName <chr>, RecipientEmail <chr>, ExternalReference <chr>, LocationLatitude <chr>,
# LocationLongitude <chr>, DistributionChannel <chr>, UserLanguage <chr>, Q1_1 <chr>

 

@am-jo Just wanted to get some clarification but are you not able to connect the API or you are not able to select a particular project and download the dataset? Based off the code it looks like you successfully connected to the API and was able to see all your survey IDs.

Thank you!


@am-jo Add the following code after what you have currently: 

write.csv(ema_survey, file = "ema_survey.csv", row.names = FALSE)

Then within R Studio environment the following CSV will show up and you will be able to view it within Excel! 

I hope this helps you out!


Leave a Reply