8000 `checkarg_time_zone()` should use allowed values from Qualtrics API instead of `base::OlsonNames()` · Issue #365 · ropensci/qualtRics · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

checkarg_time_zone() should use allowed values from Qualtrics API instead of base::OlsonNames() #365

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 agr 8000 ee to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MarriumM opened this issue Mar 15, 2025 · 13 comments
Labels

Comments

@MarriumM
Copy link
MarriumM commented Mar 15, 2025

Hello,

I am trying to download surveys from Qualtrics and have been able to connect to the API using my token and base URL (I'm guessing this on the basis of all_surveys() working with no errors).
However, the fetch_surveys does not seem to be working for me when trying to download any surveys. I get this error message:

> survey1 <- fetch_survey(surveyID = "SV_XXXX") ##Tried both copying survey id from the main Qualtrics IDs page as well as in the format of surveys$id[x]
Error in `qualtrics_response_codes()`:
! Qualtrics API reported a bad request error (400):
• Please report this on https://github.com/ropensci/qualtRics/issues

Running rlang::last_trace(drop = FALSE) gives me the following:

Backtrace:
    ▆
 1. └─qualtRics::fetch_survey(surveyID = "SV_XXX")
 2.   └─qualtRics:::export_responses_request(...)
 3.     └─qualtRics:::export_responses_init(surveyID = surveyID, body = body)
 4.       └─qualtRics:::qualtrics_api_request(...)
 5.         └─qualtRics:::qualtrics_response_codes(res)
 6.           └─rlang::abort(error_message)

I have been going over some of the previously closed issues with similar error messages and have tried all the alternatives I can find.

  • I am the owner of these surveys so that shouldn't be an issue. I am able to download/export surveys via Qualtric's web interface easily.
  • My base URL is correct as far as I can see, and I have tried both formats of organizationID.datacenterID.qualtrics.com and datacenterID.qualtrics.com when registering credentials (with no https:// in the beginning).
  • I re-generated my API token just in case that was the problem somehow but nope.
  • Running the reprex function with the fetch_surveys gives me the same error message as above:
library(qualtRics)
#> Warning: package 'qualtRics' was built under R version 4.4.3
survey1 <- fetch_survey(surveyID = "SV_XXX")
#> Error in `qualtrics_response_codes()`:
#> ! Qualtrics API reported a bad request error (400):
#> • Please report this on https://github.com/ropensci/qualtRics/issues
  • Running the code below also gave me $httpsStatus "200 - OK"
fetch_url <- qualtRics::generate_url(query = "fetchsurvey", surveyID = "SV_XXX")
raw_payload <- qualtRics:::create_raw_payload(
  label = TRUE,
  start_date = NULL,
  end_date = NULL,
  limit = NULL,
  time_zone = NULL,
  unanswer_recode = NULL,
  unanswer_recode_multi = NULL,
  include_display_order = TRUE,
  include_questions = NULL,
  breakout_sets = NULL
)

res <- qualtRics:::qualtrics_api_request("POST", url = fetch_url, body = raw_payload)
res$meta
  • In case I was getting proxied, I also ran the curl code in command prompt and got this:
C:\Users\MarriumM>curl --request GET \ --url https://organizationID.ca1.qualtrics.com/API/v3/whoami \ --header 'x-api-token: XXXXXXX'

curl: (3) URL rejected: Bad hostname
{"meta":{"httpStatus":"400 - Bad Request","error":{"errorMessage":"Expected authorization in headers, but none provided.","errorCode":"ATP_2"},"requestId":"7b76c415-69b1-4aad-8b6f-686a60f05d92"}}curl: (3) URL rejected: Bad hostname
curl: (3) URL rejected: Bad hostname

I Googled this and got another format of this command to try and got this as a result, which I am assuming means things are okay on this end and my request is not getting proxied?

 -H "X-API-TOKEN: XXXXX" -H "Content-Type: application/json"  -X GET "https://datacenterID.qualtrics.com/API/v3/whoami
{"result":{"brandId":"XX"
,"userId":"XX",
"userName":"XX",
"accountType":"XX",
"firstName":"X",
"lastName":"X",
"email":"X",
"datacenter":"viawest"},
"meta":{"requestId":"2ed8adf8-f84c-45d6-bde4-48a227236063"
,"httpStatus":"200 - OK"}}

I've tried figuring out what else could possibly be wrong but I have hit a wall at this point! Can you tell me why this is happening and/or what can I do to fix this?
I am a beginner to coding (and R!) so I am afraid I don't understand most of this other than what my searches on Google provide and so I apologize if there any obvious things I missed!

@juliasilge

This comment has been minimized.

@MarriumM

This comment has been minimized.

@juliasilge

This comment has been minimized.

@MarriumM

This comment has been minimized.

@juliasilge

This comment has been minimized.

@MarriumM

This comment has been minimized.

@juliasilge

This comment has been minimized.

@MarriumM

This comment has been minimized.

@juliasilge

This comment has been minimized.

@MarriumM

This comment has been minimized.

@MarriumM
Copy link
Author

Hi again Julia!

I don't know what happened but I randomly ran the fetch_survey function this morning and it seems like it is working for me now?

I checked to see if I was doing anything differently and the only difference I can see is that I was using Sys.setenv(TZ = "EST") to set the time zone before I ran fetch_survey() and every time I do that, it gives me the same error (bad request error (400)):

library(qualtRics)
#> Warning: package 'qualtRics' was built under R version 4.4.3

# Step 4 - List all surveys 

surveys <- all_surveys()

# Step 5 - Set time zone

Sys.setenv(TZ = "EST")

# Step 6 - Select surveys to be downloaded

mysurveys <-fetch_survey(surveyID = "SV_XXX")

#> Error in `qualtrics_response_codes()`:
#> ! Qualtrics API reported a bad request error (400):
#> • Please report this on https://github.com/ropensci/qualtRics/issues

Created on 2025-03-25 with reprex v2.1.1

But when I don't run the Sys.setenv(TZ = "EST"), the fetch_survey() works just fine:

library(qualtRics)
#> Warning: package 'qualtRics' was built under R version 4.4.3

# Step 4 - List all surveys 

surveys <- all_surveys()

# Step 6 - Select surveys to be downloaded

mysurveys <-fetch_survey(surveyID = "SV_XXXX")
#>   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
#> 
#> ── Column specification ────────────────────────────────────────────────────────
#> cols(
#>   .default = col_character(),
#>   StartDate = col_datetime(format = ""),
#>   EndDate = col_datetime(format = ""),
#>   Progress = col_double(),
#>   `Duration (in seconds)` = col_double(),
#>   Finished = col_logical(),
#>   RecordedDate = col_datetime(format = ""),
#>   RecipientLastName = col_logical(),
#>   RecipientFirstName = col_logical(),
#>   RecipientEmail = col_logical(),
#>   ExternalReference = col_logical(),
#>   LocationLatitude = col_double(),
#>   LocationLongitude = col_double()
#> )
#> ℹ Use `spec()` for the full column specifications.

# Step 7 - Save responses to a csv file

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

Created on 2025-03-25 with reprex v2.1.1

I still don't know why this made such a huge difference but the fetch_survey() definitely works now. So it was totally my bad and I am really sorry to trouble you with this for the past week or so! I can finally stop running in circles now...

@juliasilge
Copy link
Collaborator
juliasilge commented Mar 25, 2025

Ah, amazing job on figuring it out! 🙌

Looks like that is not one of the allowed timezone strings for the Qualtrics API:
https://api.qualtrics.com/c2NoOjYwNTY0-time-zone

When we check the timezone here, we should use the allowed timezone strings from the API instead of OlsonNames():

if(!time_zone %in% OlsonNames()){

@juliasilge juliasilge changed the title fetch_surveys giving Error in qualtrics_response_codes(): ! Qualtrics API reported a bad request error (400): checkarg_time_zone() should use allowed values from Qualtrics API instead of base::OlsonNames() Mar 25, 2025
@juliasilge juliasilge added the bug label Mar 25, 2025
@MarriumM
Copy link
Author

Thank you for all your help!

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

No branches or pull requests

2 participants
0