ropensci / qualtRics

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

Qualtrics API raised a bad request (400) error #156

Closed TiagoVentura closed 4 years ago

TiagoVentura commented 4 years ago

Hi all,

I am getting this error below when I try to access my Qualtrics Survey. I would really appreciate any help on what I'm doing wrong.

library(qualtRics)
qualtrics_api_credentials(api_key = "KEY", 
                          base_url = "umd.us2.qualtrics.com",
                          install = TRUE, 
                          overwrite = TRUE)
#> Your original .Renviron will be backed up and stored in your R HOME directory if needed.
#> Your Qualtrics key and base URL have been stored in your .Renviron.  
#> To use now, restart R or run `readRenviron("~/.Renviron")`
surveys <- all_surveys() 
#> Warning in check_for_warnings(cnt): Request proxied. For faster response
#> times, use this host instead: az1.qualtrics.com
surveys
#> # A tibble: 19 x 6
#>    id       name            ownerId    lastModified  creationDate  isActive
#>    <chr>    <chr>           <chr>      <chr>         <chr>         <lgl>   
#>  1 SV_000P~ Calvo_Survey-V~ UR_3UUFeY~ 2020-04-14T2~ 2020-01-15T1~ TRUE    
#>  2 SV_0PL4~ Calvo_Survey_B~ UR_3UUFeY~ 2020-04-14T1~ 2020-04-14T1~ TRUE    
#>  3 SV_39N5~ Calvo_Survey_B~ UR_3UUFeY~ 2020-04-17T1~ 2020-01-18T1~ TRUE    
#>  4 SV_5mMZ~ Twitter and Ca~ UR_a3EfA3~ 2017-01-19T2~ 2016-10-29T1~ TRUE    
#>  5 SV_74n5~ Calvo_Survey_A~ UR_3UUFeY~ 2020-04-16T1~ 2020-02-20T0~ TRUE    
#>  6 SV_0cda~ conjoint_test   UR_3k4aTH~ 2020-01-22T1~ 2020-01-22T1~ FALSE   
#>  7 SV_3DiV~ Idb_Brazil_in_~ UR_3k4aTH~ 2020-01-25T2~ 2020-01-25T2~ FALSE   
#>  8 SV_ahEA~ Experiment Twe~ UR_3k4aTH~ 2016-12-09T1~ 2016-12-09T1~ FALSE   
#>  9 SV_b8Ht~ Brasil Sem Map~ UR_3k4aTH~ 2020-01-25T2~ 2020-01-25T2~ FALSE   
#> 10 SV_d4ia~ Twitter and Ca~ UR_3k4aTH~ 2016-12-09T2~ 2016-12-09T1~ FALSE   
#> 11 SV_0pGR~ Calvo_Survey_A~ UR_0fGym3~ 2020-04-18T0~ 2019-11-28T0~ TRUE    
#> 12 SV_3dz9~ YouTube Debate~ UR_06PThN~ 2019-10-11T1~ 2019-06-25T0~ TRUE    
#> 13 SV_3E0D~ Surveys IDB     UR_0fGym3~ 2019-12-04T2~ 2019-07-10T1~ TRUE    
#> 14 SV_5d15~ Conjoint Exper~ UR_0fGym3~ 2020-04-18T0~ 2020-01-14T0~ TRUE    
#> 15 SV_795E~ Calvo_Survey    UR_0fGym3~ 2019-11-28T1~ 2019-10-10T2~ FALSE   
#> 16 SV_cHEl~ IADB Core Ques~ UR_0fGym3~ 2019-11-30T1~ 2019-10-10T2~ FALSE   
#> 17 SV_5tAX~ Chatbox Debate~ UR_cYgQ0A~ 2019-12-03T1~ 2019-07-05T1~ FALSE   
#> 18 SV_ai2G~ YouTube Debate~ UR_d0jrYM~ 2019-10-11T2~ 2019-06-26T2~ FALSE   
#> 19 SV_blOW~ Chatbox Debate~ UR_cYgQ0A~ 2020-03-31T1~ 2019-07-05T1~ TRUE

mysurvey <- fetch_survey(surveyID = surveys$id[5], 
                         verbose = TRUE, force_request = TRUE, 
                         convert = FALSE)
#> Error in qualtrics_response_codes(res): Qualtrics API raised a bad request (400) error - Please report this on
#> https://github.com/ropensci/qualtRics/issues

Created on 2020-04-18 by the reprex package (v0.3.0)

juliasilge commented 4 years ago

I'm sorry you're having trouble! You shouldn't have to reinstall your key every time, as that info is stored in your .Renviron file. What happens if you run the following, using reprex?

library(qualtRics)
all_surveys()

And if that works, what happens if you try this with the survey ID, using reprex?

library(qualtRics)
fetch_survey(surveyID = "SV_XXX") ## put your ID here
TiagoVentura commented 4 years ago

Sure! Here it goes.

library(qualtRics)
all_surveys()
#> Warning in check_for_warnings(cnt): Request proxied. For faster response
#> times, use this host instead: az1.qualtrics.com
#> # A tibble: 19 x 6
#>    id       name            ownerId    lastModified  creationDate  isActive
#>    <chr>    <chr>           <chr>      <chr>         <chr>         <lgl>   
#>  1 SV_000P~ Calvo_Survey-V~ UR_3UUFeY~ 2020-04-14T2~ 2020-01-15T1~ TRUE    
#>  2 SV_0PL4~ Calvo_Survey_B~ UR_3UUFeY~ 2020-04-14T1~ 2020-04-14T1~ TRUE    
#>  3 SV_39N5~ Calvo_Survey_B~ UR_3UUFeY~ 2020-04-17T1~ 2020-01-18T1~ TRUE    
#>  4 SV_5mMZ~ Twitter and Ca~ UR_a3EfA3~ 2017-01-19T2~ 2016-10-29T1~ TRUE    
#>  5 SV_74n5~ Calvo_Survey_A~ UR_3UUFeY~ 2020-04-16T1~ 2020-02-20T0~ TRUE    
#>  6 SV_0cda~ conjoint_test   UR_3k4aTH~ 2020-01-22T1~ 2020-01-22T1~ FALSE   
#>  7 SV_3DiV~ Idb_Brazil_in_~ UR_3k4aTH~ 2020-01-25T2~ 2020-01-25T2~ FALSE   
#>  8 SV_ahEA~ Experiment Twe~ UR_3k4aTH~ 2016-12-09T1~ 2016-12-09T1~ FALSE   
#>  9 SV_b8Ht~ Brasil Sem Map~ UR_3k4aTH~ 2020-01-25T2~ 2020-01-25T2~ FALSE   
#> 10 SV_d4ia~ Twitter and Ca~ UR_3k4aTH~ 2016-12-09T2~ 2016-12-09T1~ FALSE   
#> 11 SV_0pGR~ Calvo_Survey_A~ UR_0fGym3~ 2020-04-18T0~ 2019-11-28T0~ TRUE    
#> 12 SV_3dz9~ YouTube Debate~ UR_06PThN~ 2019-10-11T1~ 2019-06-25T0~ TRUE    
#> 13 SV_3E0D~ Surveys IDB     UR_0fGym3~ 2019-12-04T2~ 2019-07-10T1~ TRUE    
#> 14 SV_5d15~ Conjoint Exper~ UR_0fGym3~ 2020-04-18T0~ 2020-01-14T0~ TRUE    
#> 15 SV_795E~ Calvo_Survey    UR_0fGym3~ 2019-11-28T1~ 2019-10-10T2~ FALSE   
#> 16 SV_cHEl~ IADB Core Ques~ UR_0fGym3~ 2019-11-30T1~ 2019-10-10T2~ FALSE   
#> 17 SV_5tAX~ Chatbox Debate~ UR_cYgQ0A~ 2019-12-03T1~ 2019-07-05T1~ FALSE   
#> 18 SV_ai2G~ YouTube Debate~ UR_d0jrYM~ 2019-10-11T2~ 2019-06-26T2~ FALSE   
#> 19 SV_blOW~ Chatbox Debate~ UR_cYgQ0A~ 2020-03-31T1~ 2019-07-05T1~ TRUE

library(qualtRics)
fetch_survey(surveyID = "SV_000P4mbxyfjnn81")
#> Error in qualtrics_response_codes(res): Qualtrics API raised a bad request (400) error - Please report this on
#> https://github.com/ropensci/qualtRics/issues

Created on 2020-04-20 by the reprex package (v0.3.0)

juliasilge commented 4 years ago

Thanks for your patience @TiagoVentura!

Can you now try out the following code, but with your survey ID?

library(qualtRics)
my_survey <- "SV_5BJRo2RGHajIlOB"

fetch_url <- qualtRics:::create_fetch_url(Sys.getenv("QUALTRICS_BASE_URL"), my_survey)
fetch_url
#> [1] "conjoint.co1.qualtrics.com/API/v3/surveys/SV_5BJRo2RGHajIlOB/export-responses/"

raw_payload <- qualtRics:::create_raw_payload(
  label = TRUE,
  start_date = NULL,
  end_date = NULL,
  unanswer_recode = NULL,
  unanswer_recode_multi = NULL,
  include_display_order = TRUE,
  limit = NULL,
  time_zone = NULL,
  include_questions = NULL,
  breakout_sets = TRUE
)
raw_payload
#> {"useLabels":true,"includeDisplayOrder":true,"breakoutSets":true,"format":"csv"}

qualtRics:::qualtrics_api_request("POST", url = fetch_url, body = raw_payload)
#> $result
#> $result$progressId
#> [1] "ES_8okwtF6BtE5yjzv"
#> 
#> $result$percentComplete
#> [1] 0
#> 
#> $result$status
#> [1] "inProgress"
#> 
#> 
#> $meta
#> $meta$requestId
#> [1] "1af9a7b6-fb64-4253-b78c-2368ddd98c21"
#> 
#> $meta$httpStatus
#> [1] "200 - OK"

Created on 2020-04-29 by the reprex package (v0.3.0)

juliasilge commented 4 years ago

I'm going to close this issue for now @TiagoVentura. Let us know if you continue to have problems! 🙌

lirabenjamin commented 2 years ago

Hi Julia! I love your YouTube! I'm getting the same error.

Here's what I see.

> fetch_url <- qualtRics:::create_fetch_url(Sys.getenv("upenn.co1.qualtrics.com"), my_survey)
> fetch_url
[1] "https:///API/v3/surveys/SV_006h1HxAXDpxmhU/export-responses/"
> raw_payload <- qualtRics:::create_raw_payload(
+   label = TRUE,
+   start_date = NULL,
+   end_date = NULL,
+   unanswer_recode = NULL,
+   unanswer_recode_multi = NULL,
+   include_display_order = TRUE,
+   limit = NULL,
+   time_zone = NULL,
+   include_questions = NULL,
+   breakout_sets = TRUE
+ )
> raw_payload
{"useLabels":true,"includeDisplayOrder":true,"breakoutSets":true,"format":"csv"} 
> qualtRics:::qualtrics_api_request("POST", url = fetch_url, body = raw_payload)
Error in curl::curl_fetch_memory(url, handle = handle) : 
  SSL: no alternative certificate subject name matches target host name 'API'
> fetch_url <- qualtRics:::create_fetch_url(Sys.getenv("upenn.co1.qualtrics.com"), my_survey)
> fetch_url
[1] "https:///API/v3/surveys/SV_006h1HxAXDpxmhU/export-responses/"
> raw_payload <- qualtRics:::create_raw_payload(
+   label = TRUE,
+   start_date = NULL,
+   end_date = NULL,
+   unanswer_recode = NULL,
+   unanswer_recode_multi = NULL,
+   include_display_order = TRUE,
+   limit = NULL,
+   time_zone = NULL,
+   include_questions = NULL,
+   breakout_sets = TRUE
+ )
> raw_payload
{"useLabels":true,"includeDisplayOrder":true,"breakoutSets":true,"format":"csv"} 
> qualtRics:::qualtrics_api_request("POST", url = fetch_url, body = raw_payload)
Error in curl::curl_fetch_memory(url, handle = handle) : 
  SSL: no alternative certificate subject name matches target host name 'API'
juliasilge commented 2 years ago

@lirabenjamin Looks like something is not quite right with your base URL. You should have an environment variable called QUALTRICS_BASE_URL that stored something like yourorganizationid.yourdatacenterid.qualtrics.com without a scheme such as https://.

What happens if you call Sys.getenv("QUALTRICS_BASE_URL")? You should see something like this, but with your base URL:

Sys.getenv("QUALTRICS_BASE_URL")
#> [1] "conjoint.co1.qualtrics.com"

Created on 2021-10-01 by the reprex package (v2.0.1)

That is what lets qualtRics create URLs and query the API for you.

lirabenjamin commented 2 years ago

Hi Julia,

That fixed it! The base URL offered on the Qualtrics settings page is not the same as the url I go on qualtrics itself. Which is weird. Using the one in the address bar rather than on Qualtrics settings worked!

Thanks for your work and fast response! On Fri, Oct 1, 2021 at 12:11 Julia Silge @.***> wrote:

@lirabenjamin https://github.com/lirabenjamin Looks like something is not quite right with your base URL. You should have an environment variable called QUALTRICS_BASE_URL that stored something like yourorganizationid.yourdatacenterid.qualtrics.com without a scheme such as https://.

What happens if you call Sys.getenv("QUALTRICS_BASE_URL")? You should see something like this, but with your base URL:

Sys.getenv("QUALTRICS_BASE_URL")#> [1] "conjoint.co1.qualtrics.com"

Created on 2021-10-01 by the reprex package https://reprex.tidyverse.org (v2.0.1)

That is what lets qualtRics create URLs and query the API for you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ropensci/qualtRics/issues/156#issuecomment-932363957, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE5FRV4KOGSUAJOGVFU3LDTUEXMT3ANCNFSM4MLQM5QA . 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.