ropensci / qualtRics

Download ⬇️ Qualtrics survey data directly into R!
https://docs.ropensci.org/qualtRics
Other
215 stars 70 forks source link

Authentication issues when deploying qualtRics code to RStudio Connect #242

Closed Trabendo-daze closed 2 years ago

Trabendo-daze commented 2 years ago

I'm able to access survey data locally in RStudio, but when I deploy the code to RStudio Connect, I'm hit with authentication errors. I have been able to deploy this same code in the past (as recently as a month ago) with no issues, but this problem has popped up recently.

Example code:

qualtrics_api_credentials(api_key = Sys.getenv("QUALTRICS_API_KEY"), 
                              base_url = Sys.getenv("QUALTRICS_BASE_URL"))

    surveys <- all_surveys() 
    survey_df_qualtrics <- fetch_survey(surveyID = my_survey_id, 
                                 verbose = TRUE,
                                 force_request = TRUE)

Example error (only on RStudio Connect):

11/22 18:21:07.727 (GMT)
Quitting from lines 25-46 (survey_df_creation_pin.Rmd)
11/22 18:21:07.727 (GMT)
Error in qualtrics_response_codes(res) :
11/22 18:21:07.727 (GMT)
Qualtrics API raised an authentication (401) error - you may not have the
11/22 18:21:07.727 (GMT)
required authorization. Please check your API key and root url.

I've tried resetting my API key, but no dice. Any ideas?

juliasilge commented 2 years ago

Have you gone in to set the environment variables for this piece of content on RStudio Connect, as shown here ("Vars (Environment Variables)")? You might want to check that there are really two variables called QUALTRICS_API_KEY and QUALTRICS_BASE_URL saved on that published content on RStudio Connect.

Trabendo-daze commented 2 years ago

Yes, I should have clarified that those variables are set, and that I have double and triple-checked their values. I've gotten a different error when those are not filled in, so I'm fairly certain I've entered the variables correctly.

juliasilge commented 2 years ago

I just tested an .Rmd on our demo RStudio Connect and it appears to be working. I made a very simple file and published it, then added the two environment variables.

One thing you might try is republishing the doc so that it only does this:

Sys.getenv("QUALTRICS_API_KEY")
Sys.getenv("QUALTRICS_BASE_URL")
knitr::knit_exit()

That should only print out your credentials (hopefully successfully) so you can see they are there, but then exit before running the rest of the file.

Trabendo-daze commented 2 years ago

Thanks for looking into this. A colleague has reported similar issues, so might be something with our RSC instance? I'll look into this more after Thanksgiving and follow up on here.

Trabendo-daze commented 2 years ago

Alright, so I ran the code chunk in your comment on 11/23 and I found something really weird.

When I knit the chunk locally, it acts as intended, printing my api key and base url. When I deploy the document with source code, it knits instantly, meaning that it doesn't error out once before I add the variables to that document. Furthermore, it prints credentials that aren't mine.

When I do add my own variables, it still prints the other credentials out. It seems like RSC is somehow referencing some sort of globally stored API key and base url variables? Maybe I can solve this by just renaming my variables, but this is definitely an issue with our RSC instance and probably has nothing to do with qualtRics. Gonna post something in our R slack channel.

Trabendo-daze commented 2 years ago

Renaming the variable something other than QUALTRICS_API_KEY solves the issue, but this shouldn't be a problem, applications should be independent from each other, right?

juliasilge commented 2 years ago

It sounds like someone has put Qualtrics credentials in some kind of global configuration file (.Rprofile or .Renviron, perhaps) on the machine where you have RStudio Connect installed. It is possible to do this with a supervisor script, like these folks are talking about.

chrisumphlett commented 2 years ago

Yes. I wish you could use an env var across pieces of content because I've had to change one in 10 different places before.

On Mon, Nov 29, 2021 at 2:56 PM Brendon Kaufman @.***> wrote:

Renaming the variable something other than QUALTRICS_API_KEY solves the issue, but this shouldn't be a problem, applications should be independent from each other, right?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ropensci/qualtRics/issues/242#issuecomment-981966386, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABXAL4RMYE7YEQO564JGZUDUOPLHLANCNFSM5IRV66IQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Trabendo-daze commented 2 years ago

Yeah, I've requested that feature from our RSC reps as well. At Indeed, we have this on our internal Python-based data science platform and it's really nice!

Closing this because it's our problem, not yours. Thanks!