ropensci / qualtRics

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

Bad Request (400) Raised #50

Closed Delkine closed 7 years ago

Delkine commented 7 years ago

Japser,

After almost 2 weeks of error free use of script I'm now repeatedly getting a bad request (400) error when it is run. The script is unchanged. Has anything changed with qualtRics or with the API that would cause this error to be raised now? Do you need to see the whole script or part of the script?

Delkine

JasperHG90 commented 7 years ago

Hi Delkine,

I'm not sure what you mean when you refer to 'the script'. It would help to see it.

Does qualtRics work stand-alone? Or does it fail across the board?

I just tested it with newest version of R and it works for me.

Delkine commented 7 years ago

Jasper,

Here is the Script that has worked until last Friday. I've deleted some irrelevant code (API Key, Instructions etc.)

This script is use to Get Survey Responses from Qualtrics API.

Start

Set Working Directory to R Scripts

setwd("c:/Users/del/Dropbox/Polynesian Cultural Center/Shared PCC/Qualtrics Data")

library(qualtRics) Found a .qualtRics.yml configuration file in c:/Users/del/Dropbox/Polynesian Cultural Center/Shared PCC/Qualtrics Data. Using these credentials.

surveys <- getSurveys()

Read lastResponseId for the saved value from previous runs.

lastId.rds <-readRDS("lastId.rds")

Provide surveys$id (number that is in brackets) with one associated with chosen survey & save_dir location to one of your choosing

mysurvey <- getSurvey(surveyID = surveys$id[9],

  • save_dir = "/users/del/dropbox/Polynesian Cultural Center/Shared PCC/Qualtrics Data/",
  • lastResponseId = lastId.rds,
  • verbose=TRUE,
  • uselabels=FALSE,
  • force_request = TRUE)

    HERE IS THE ERROR

    Error in qualtRicsResponseCodes(res, raw = raw) : Qualtrics API raised a bad request (400) error - Please report this on https://github.com/JasperHG90/qualtRics/issues

    Get new lastResponseId from current download for next iteration

    lastId.rds <- tail(mysurvey$ResponseID,1)

    THIS ERROR IS NEW TOO

    Error in tail(mysurvey$ResponseID, 1) : object 'mysurvey' not found

    Save new lastResponseId for next iteration

    saveRDS(lastId.rds, file = "lastId.rds")

File names and locations can be changed to suit your needs.

mysurvey <- readRDS(file = "/Users/del/Dropbox/Polynesian Cultural Center/Shared PCC/Qualtrics Data/SV_1ZVShEVtp6thqkd.rds") # Initial file is output as *.RDS file.
write.csv(mysurvey, file = "/Users/del/Dropbox/Polynesian Cultural Center/Shared PCC/Qualtrics Data/mshare2.df.csv", row.names = FALSE) # RDS file is converted to csv.

End

JasperHG90 commented 7 years ago

Hi Del,

May I ask why you closed this thread? Was your issue solved?

J.

Delkine commented 7 years ago

Sorry, I didn't intend to close it. It should still be open. Do I need to do something to open it back up again?

JasperHG90 commented 7 years ago

To me, this looks like an error caused by passing a bad response id .

Try the following:

1) try to download your survey without passing the responseId 2) if this works, take a random responseId from the survey and use it to download your results again 3) check the RDS file in which your responseId is stored. See if it is malformed in any way. 4) in any case, if step 2) works out for you try rebooting your script with the new latest responseId

J.

Delkine commented 7 years ago

Thank you for your help. I’ll let you know if this solves the problem.

Del

Sent from Mail for Windows 10

From: Jasper Ginn Sent: Wednesday, October 18, 2017 12:13 AM To: JasperHG90/qualtRics Cc: Delkine; State change Subject: Re: [JasperHG90/qualtRics] Bad Request (400) Raised (#50)

To me, this looks like an error caused by passing a bad response id . Try the following:

  1. try to download your survey without passing the responseId
  2. if this works, take a random responseId from the survey and use it to download your results again
  3. check the RDS file in which your responseId is stored. See if it is malformed in any way.
  4. in any case, if step 2) works out for you try rebooting your script with the new latest responseId J. — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.
JasperHG90 commented 7 years ago

Hi Del,

Could you let me know if this is still an issue for you?

Thanks.

J.

Delkine commented 7 years ago

Hi Jasper, Off & on it & other errors seem to occur.  I'm not a R programmer so finding out what the problem is can be quite a challenge.  I can get to run now but I'm really not sure what the problem was. Your package is very valuable to us but as yet it is not "set & forget." Do you have any advice on how debug our scripts? Del 

Sent from my Verizon, Samsung Galaxy smartphone -------- Original message --------From: Jasper Ginn notifications@github.com Date: 10/24/17 12:21 AM (GMT-08:00) To: JasperHG90/qualtRics qualtRics@noreply.github.com Cc: Delkine dnebeker@cox.net, State change state_change@noreply.github.com Subject: Re: [JasperHG90/qualtRics] Bad Request (400) Raised (#50) Hi Del, Could you let me know if this is still an issue for you? Thanks. J.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/JasperHG90/qualtRics","title":"JasperHG90/qualtRics","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/JasperHG90/qualtRics"}},"updates":{"snippets":[{"icon":"PERSON","message":"@JasperHG90 in #50: Hi Del,\r\n\r\nCould you let me know if this is still an issue for you?\r\n\r\nThanks.\r\n\r\nJ."}],"action":{"name":"View Issue","url":"https://github.com/JasperHG90/qualtRics/issues/50#issuecomment-338898198"}}}

Delkine commented 7 years ago

Jasper, I'm still getting inconsistent behavior from this code. I hope you can point me in the right direction. I thought everything was running as planned but then I get an error. I get this error off and on but not consistently. This code is run from RStudio and is scheduled to run every night automatically.

Code starts below this line.


setwd("c:/users/del/Qualtrics Data")

library(qualtRics) registerOptions()

surveys <- getSurveys()

lastid1.rds <-"R_RISFrOdBtIR1kyZ" ## Remove comment marks in col. 1 when running & no lastid has been previously stored in wd.

## Previously stored lastid will be overwritten. Replace value in " " with responseid desired.

## Save lastid1.rds to a file to store initial value and subsequent values for lastResponseId

saveRDS(lastid1.rds, file="lastid1.rds") ## Remove comment mark in col. 1 when running & no lastid has been previouly stored in wd.

## Read lastResponseId for the saved value from previous runs.

lastId2.rds <-readRDS("c:/users/del/Qualtrics Data/lastId1.rds")

Comment

At this point I get the following error:

Error in readRDS("c:/users/del/Qualtrics Data/lastId1.rds") : error reading from connection

Comment

The file exists on the wd and it has a valid responseID saved in it. Once this error occurs there are several other errors as code runs as having this value is the needed

## Provide surveys$id (number that is in brackets) with one associated with chosen survey 

mysurvey <- getSurvey(surveyID = surveys$id[9], save_dir = "/users/del/Qualtrics Data/", lastResponseId = lastId2.rds, verbose=TRUE, uselabels=FALSE, force_request = TRUE)

## Get new lastResponseId from current download for next iteration

lastId1.rds <- tail(mysurvey$ResponseID,1)

## Save new lastResponseId for next iteration

saveRDS(lastId1.rds, file = "c:/users/del/Qualtrics Data/lastId1.rds")

mysurvey <- readRDS(file = "c:/users/del/Qualtrics Data/SV_1ZVShEVtp6thqkd.rds") # Initial file is output as *.RDS file.
write.csv(mysurvey, file = "c:/users/del/Qualtrics Data/mshare2.df.csv", row.names = FALSE) # RDS file is converted to csv.

JasperHG90 commented 7 years ago

Hi Del,

I want to help you, but as I'm sure you understand, it's close to impossible for me to debug your code from a distance. This is especially true since the error you are experiencing does not occur in my package, but in a generic R function.

First, a couple of things that, in general, are problematic about your code:

  1. Don't use spaces in folder names, use underscores: "c:/users/del/Qualtrics Data/SV_1ZVShEVtp6thqkd.rds" --> "c:/users/del/Qualtrics_Data/SV_1ZVShEVtp6thqkd.rds"
  2. Don't use something like '.df.csv' for your filenames. Names that start with '.' are reserved for the operating system and are used to denote file extension. Again, use underscores. --> 'myfile_df.csv'

Now, I don't know about your current setup, but try the following:

Hope that helps.

I'm closing this issue because the error is not related to the qualtRics package.

Best,

Jasper.