Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve survey translation #245

Open
POP-PA opened this issue Nov 29, 2021 · 4 comments
Open

Retrieve survey translation #245

POP-PA opened this issue Nov 29, 2021 · 4 comments

Comments

@POP-PA
Copy link

POP-PA commented Nov 29, 2021

Would it be possible to retrieve survey translation? Especially for extract_colmap and fetch_survey?

@juliasilge
Copy link
Collaborator

Looks like we could use the GET endpoint for survey translations, with a language code:
https://api.qualtrics.com/api-reference/b3A6NjExMDk-get-survey-translations-json

@Celia-C
Copy link

Celia-C commented Sep 28, 2022

I am new to Qualtrics, and I am working on an R Markdown report for a survey in English (base language) and 2 other add-on languages. This report needs to be done in all three languages and auto-refreshed for future data and survey changes. I did some research, and want to post some findings here to help other people move forward and to have a record for myself.

  1. You will need "Edit" and "Survey Translation" permission to make the API connection work.
  2. qualtrics_api_request() function is the easiest way, which is included in the utils.R. Please note that library(qualtRics) will not allow you to access this function. What I did is that I copied the entire utils.R to my local and sourced it in my R code. In this way, you will not able to get the most updated version of this function, but the current version is good enough for me.
  3. You will also need checks.R to make qualtrics_api_request() function run properly. Copy-pasted to my local and sourced in the R code.

Example code to get Survey Translations JSON through API

library(qualtRics)
source("[your working directory]/qualtRics_utils.R") ## the utils.R from qualtRics package
source("[your working directory]/qualtRics_checks.R") ## the checks.R from qualtRics package
language_code.V <- c("EN","ES","PT") ## replace with valid survey language code
for(ilang in 1:length(language_code.V))
{
language_code <- language_code.V[ilang]
survey_url <- qualtRics::generate_url(query = "metadata", surveyID = "[your survey ID]")
survey_url <- paste0(survey_url,"translations/",language_code,"/")
resp <- qualtrics_api_request(verb = "GET", as = "parsed", url = survey_url)
assign(paste0("resp_",language_code), resp)
}

@jmobrien
Copy link
Collaborator

jmobrien commented Sep 29, 2022

Thanks, @Celia-C. Yes, if there's demand for this we should add something so these kind of workarounds aren't necessary.

BTW, if you really need an non-exported functions in an R package, you can use three colons, i.e., qualtRics:::qualtrics_api_request(). The function when run can then still reference other internal package functions, meaning you won't have to load utils.R OR checks.R. (Obviously our own focus remains on building the actual functionality, but just an FYI)

One other thing, @Celia-C -- can you share with us an example of what comes back from this endpoint? That might be useful to plan for what we might do with it/where we might put its output.

@juliasilge -- Apparently we've been exporting generate_url() since I added it last year? That was my mistake--and there's no reason to not just fix it, right? Just making sure there's not some use case I'm missing.

(Definitely needs better documentation if we keep it, though.)

@juliasilge
Copy link
Collaborator

Just to reiterate what @jmobrien said, you wouldn't necessarily need to copy the code from the qualtRics package to your own computer; instead you can use ::: to get to unexported functions:

survey_url <- qualtRics::generate_url(query = "metadata", surveyID = "SV_3gbwq8aJgqPwQDP")
survey_url <- paste0(survey_url, "translations/", "EN", "/")
resp <- qualtRics:::qualtrics_api_request(verb = "GET", as = "parsed", url = survey_url)
resp
#> $meta
#> $meta$httpStatus
#> [1] "200 - OK"
#> 
#> $meta$requestId
#> [1] "03f4f0bb-db1a-4881-8e57-7b3e933c9090"
#> 
#> 
#> $result
#> $result$QID17_QuestionText
#> [1] "Have you ever contacted customer service about your beskar armor?"
#> 
#> $result$SurveyTitle
#> [1] "Online Survey Software | Qualtrics Survey Solutions"
#> 
#> $result$QID16_QuestionText
#> [1] "Overall, how satisfied are you with your beskar armor?"
#> 
#> $result$QID63_Choice2
#> [1] "Weekly"
#> 
#> $result$QID63_Choice1
#> [1] "<span style=\"color:#8e44ad;\">Daily</span>"
#> 
#> $result$QID22_QuestionText
#> [1] "If you would like to share any additional comments or experiences about your beskar armor, please enter them below."
#> 
#> $result$QID63_Choice5
#> [1] "Do not use"
#> 
#> $result$QID63_Choice4
#> [1] "<a href=\"https://www.instagram.com/p/B5qn5ath0ij/?hl=en\">Less often</a>"
#> 
#> $result$QID63_Choice3
#> [1] "Once a <span style=\"background-color:#9b59b6;\">month</span>"
#> 
#> $result$QID17_Choice2
#> [1] "No"
#> 
#> $result$QID16_Choice2
#> [1] "<a href=\"https://www.gq.com/story/werner-herzog-baby-yoda\">Somewhat dissatisfied</a>"
#> 
#> $result$QID16_Choice1
#> [1] "<em>Extremely</em> dissatisfied"
#> 
#> $result$QID16_Choice4
#> [1] "<a href=\"https://giphy.com/explore/baby-yoda\">Somewhat satisfied</a>"
#> 
#> $result$QID16_Choice3
#> [1] "<span style=\"background-color:#e74c3c;\">Neither</span> <span style=\"background-color:#e67e22;\">satisfied</span> <span style=\"background-color:#f1c40f;\">nor</span> <span style=\"background-color:#27ae60;\">dissatisfied</span>"
#> 
#> $result$QID17_Choice1
#> [1] "Yes"
#> 
#> $result$QID16_Choice5
#> [1] "<strong>Extremely</strong> satisfied"
#> 
#> $result$SurveyDescription
#> [1] "Qualtrics sophisticated online survey software solutions make creating online surveys easy. Learn more about Research Suite and get a free account today."
#> 
#> $result$QID18_QuestionText
#> [1] "Have all problems been resolved to your complete satisfaction?"
#> 
#> $result$QID18_Choice3
#> [1] "No, the problem was not resolved \n<video class=\"qmedia\" controls=\"true\" height=\"168\" preload=\"auto\" width=\"268\"><source src=\"https://i.imgur.com/i40m72o.mp4\" type=\"video/mp4\" /><embed align=\"middle\" autoplay=\"false\" bgcolor=\"white\" class=\"qmedia\" controller=\"true\" height=\"168\" pluginspage=\"http://www.apple.com/quicktime/download/\" src=\"https://i.imgur.com/i40m72o.mp4\" type=\"video/quicktime\" width=\"268\" /></video>\n"
#> 
#> $result$QID63_QuestionText
#> [1] "How often do you typically use your beskar armor?"
#> 
#> $result$QID18_Choice1
#> [1] "Yes, by the tribe or its representatives \n<video class=\"qmedia\" controls=\"true\" height=\"268\" preload=\"auto\" width=\"268\"><source src=\"https://i.imgur.com/QlAme0q.mp4\" type=\"video/mp4\" /><embed align=\"middle\" autoplay=\"false\" bgcolor=\"white\" class=\"qmedia\" controller=\"true\" height=\"268\" pluginspage=\"http://www.apple.com/quicktime/download/\" src=\"https://i.imgur.com/QlAme0q.mp4\" type=\"video/quicktime\" width=\"268\" /></video>\n"
#> 
#> $result$QID18_Choice2
#> [1] "Yes, by me or someone outside the tribe \n<video class=\"qmedia\" controls=\"true\" height=\"268\" preload=\"auto\" width=\"268\"><source src=\"https://i.imgur.com/5sRVO4d.mp4\" type=\"video/mp4\" /><embed align=\"middle\" autoplay=\"false\" bgcolor=\"white\" class=\"qmedia\" controller=\"true\" height=\"268\" pluginspage=\"http://www.apple.com/quicktime/download/\" src=\"https://i.imgur.com/5sRVO4d.mp4\" type=\"video/quicktime\" width=\"268\" /></video>\n"
#> 
#> $result$QID19_QuestionText
#> [1] "Why not?"

Created on 2022-09-29 with reprex v2.0.2

I am actually wondering if we should export qualtrics_api_request() so that folks can extend it when we haven't added support for certain endpoints yet. This would involve keeping generate_url() exported (and documenting it) and then also exporting and documenting qualtrics_api_request(). It might be nice to let folks have an easier way to do more customized calls. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants