ropensci / qualtRics

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

Qualtrics API reported a bad request error (400) #359

Open Saikoneti-25 opened 1 week ago

Saikoneti-25 commented 1 week ago

library(qualtRics)

Api info here

qualtrics_api_credentials(api_key = "api id",

  • base_url = "base url") To install your credentials for use in future sessions, run this function with install = TRUE.

    Time Zone

    Sys.setenv(TZ = "EST")

Select survey to download

thesurvey <- fetch_survey(surveyID = "---") Error in qualtrics_response_codes(): ! Qualtrics API reported a bad request error (400): • Please report this on https://github.com/ropensci/qualtRics/issues Run rlang::last_trace() to see where the error occurred. rlang::last_trace() Error: object 'rlang::last_trace()' not found Error in qualtrics_response_codes(): ! Qualtrics API reported a bad request error (400): • Please report this on https://github.com/ropensci/qualtRics/issues Run rlang::last_trace() to see where the error occurred. rlang::last_trace() <error/rlang_error> Error in qualtrics_response_codes(): ! Qualtrics API reported a bad request error (400): • Please report this on https://github.com/ropensci/qualtRics/issues

Backtrace: ▆

  1. └─qualtRics::fetch_survey(surveyID = "----")
  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) Run rlang::last_trace(drop = FALSE) to see 1 hidden frame. rlang::last_trace(drop = FALSE) <error/rlang_error> Error in qualtrics_response_codes(): ! Qualtrics API reported a bad request error (400): • Please report this on https://github.com/ropensci/qualtRics/issues

    Backtrace: ▆

  6. └─qualtRics::fetch_survey(surveyID = "------")
  7. └─qualtRics:::export_responses_request(...)
  8. └─qualtRics:::export_responses_init(surveyID = surveyID, body = body)
  9. └─qualtRics:::qualtrics_api_request(...)
  10. └─qualtRics:::qualtrics_response_codes(res)
  11. └─rlang::abort(error_message)
juliasilge commented 1 week ago

Hello there, @Saikoneti-25! The most common source of this error is Qualtrics proxying your request. Do you see any messages about proxying? For example, what do you see when you run this at the command line (not in R)?

curl --request GET \
--url https://XXX.qualtrics.com/API/v3/whoami \
--header 'x-api-token: YOURLONGAPITOKENHERE'

You would need to use your URL and your API token. Do you see anything in the results like:

Notice: Request proxied. For faster response times, use this host instead:

Another thing you can try is to run this code to see a bit more detail about what is happening, with your survey ID:

fetch_url <- qualtRics::generate_url(query = "exportresponses", surveyID = "SV_83XXXXX")
raw_payload <- qualtRics:::create_raw_payload(
        format = "csv",
        useLabels = TRUE,
        startDate = NULL,
        endDate = NULL,
        timeZone = NULL,
        limit = NULL,
        seenUnansweredRecode = NULL,
        multiselectSeenUnansweredRecode = NULL,
        includeDisplayOrder = TRUE,
        questionIds = NULL,
        embeddedDataIds = NULL,
        surveyMetadataIds = NULL,
        breakoutSets = NULL
      )

res <- qualtRics:::qualtrics_api_request("POST", url = fetch_url, body = raw_payload)
res$meta
#> $requestId
#> [1] "88314239-93ac-43d6-a0d1-93180f4476b8"
#> 
#> $httpStatus
#> [1] "200 - OK"

Created on 2024-07-31 with reprex v2.1.1