Closed klittle314 closed 8 years ago
What version of Rmonkey are you using? (you can see this using sessionInfo()
).
R version 3.2.0 (2015-04-16) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages: [1] stats graphics grDevices utils datasets [6] methods base
other attached packages: [1] Rmonkey_0.2.11
loaded via a namespace (and not attached):
[1] httr_1.0.0 R6_2.1.0 magrittr_1.5
[4] plyr_1.8.3 tools_3.2.0 rstudioapi_0.3.1
[7] RCurl_1.95-4.7 curl_0.9.2 Rcpp_0.12.0
[10] stringi_0.5-5 jsonlite_0.9.16 stringr_1.0.0
[13] httpuv_1.3.3 bitops_1.0-6
checking your createsurvey function: when the body element b is created as a list and converted to JSON, the input and output are given:
INPUT b <- list(survey=list(from_survey_id=as.character(s[[10]]$survey_id), survey_title="Test Title"), collector=list(type="email", name="Email_1", recipients=list(c('zrubin@ihi.org'))), email_message=list(subject="Test survey", reply_email="klittle@iecodesign.com", body="Test message"))
b <- toJSON(b,auto_unbox=FALSE)
OUTPUT
b {"survey":{"from_survey_id":"64177053","survey_title":"Test Title"},"collector":{"type":"email","name":"Email_1","recipients":["zrubin@ihi.org"]},"email_message":{"subject":"Test survey","reply_email":"klittle@iecodesign.com","body":"Test message"}}
However, when I look at the API guide https://developer.surveymonkey.com/mashery/create_flow , the call to create_flow has a different structure in the recipients list:
'{"survey": {"template_id": "568", "survey_title": "Ice and Fire Event"}, "collector": {"type": "email", "name" : "email invite", "recipients": [{"email": "xyzstannis@surveymonkey.com", "first_name": "Stannis", "last_name": "Baratheon", "custom_id": "94301"}, {"email": "xyzjoffrey@surveymonkey.com", "first_name": "Joffrey", "last_name": "Baratheon", "custom_id": "94401"}, {"email": "renly@surveymonkey"}]}, "email_message" : { "subject" : "Ice and Fire event" , "reply_email" : "xyzcersei@surveymonkey.com", "body_text" : "We are conducting a survey, and your response would be appreciated. Here is a link to the survey: [SurveyLink] This link is uniquely tied to this survey and your email address. Please do not forward this message. Thanks for your participation! Please note: If you do not wish to receive further emails from us, please click the link below, and you will be automatically removed from our mailing list. [RemoveLink]"}}'
SPECIFIC OBSERVATION: In the SurveyMonkey JSON code, there is a pair of braces {} enclosing the elements of the recipient list, but there are no braces in the R generated code.
I have no knowledge of JSON so I don't know if this difference has any meaning, I am blindly working my way through line by line in your function and varying conditions.
will let you know if i make any progress (when I work thru your function code and manually call POST and content, I get the same error as before, which makes me think I have read your function correctly....
Kevin
Succeeded in creating a survey, copying an existing survey. There appear to be a couple of issues in your createsurvey function.
First, I don't know how to modify the list structure to create the missing braces discussed in previous comment, so I generated the required string and manually inserted the braces. Will use sub function working on strings as last resort if I can't figure out list syntax.
Second, the parameters in the email message list had an error--your code had the parameter body but the SM API specifies body_text: Thus the list should be email_message=list(subject="Test survey", reply_email="klittle@iecodesign.com", body_text="Test message"))
Finally, there are three required links in the body_text string unless some global options are set in the SM account, as shown in the example in the previous comment clipped from the SM API guide:
[SurveyLink] [OptOutLink] [FooterLink]
These links are described on the SM API http://help.surveymonkey.com/articles/en_US/kb/SurveyLink-and-RemoveLink?uid=JZd7KabOVdPv_2FF9lOdUb2juVQK3NX8Z5JXivGw3wXgx6cCwyxsLbfCsqDUkMJSFWb2lQemqeCG6JoHK9z_2Fg2gpyRaP_2B_2F2xOfu_2F5B6In0oKU_3D
thanks for the work on the package.
Unfortunately, I can't work on this for a couple of weeks (I'm moving internationally). Would you be able to put together a pull request that fixes this? If not, it's no problem; I just can't get to it until the second week of September.
Yes, I will get to this next week or let you know if I have failed to do things the right way. It will be good practice in working with GitHub, I am incorporating into project workflow.
Have a good move, thanks again for working on the package.
PS We built by hand (with for loops, we may redo with apply family) a way to get a summary data frame translating the coded answers in SurveyMonkey into a human friendly form. this may be turned into a function used in ShinyApp to manage "many" surveys. Intend to share chunks of this work via GitHub, in fall.
Great! I'll look forward to the PR. Feel free to submit any changes you think would be helpful (as separate commits). And don't forget to add yourself as a contributor to the DESCRIPTION file. Thanks!
OK, sent Pull Request, updating createsurvey.R, createsurvey.Rd, and DOCUMENTATION file. I had a couple of questions still unclear, will test some more about required parameters (e.g. email_body).
Still getting the hang of GitHub so I may not have done things exactly right.
thx
Kevin
running the createsurvey function generates an error, e.g your example from HELP file
$status [1] 3
$errmsg [1] "additional properties not defined by 'properties' are not allowed in field '_data' in recipient."
Warning message: In createsurvey(survey = s[[1]]$survey_id, title = "Copied survey", : An error occurred: additional properties not defined by 'properties' are not allowed in field '_data' in recipient.
This appears to be a known error in calls to SurveyMonkey API, e.g. http://stackoverflow.com/questions/23660837/additional-properties-error-in-survey-monkey-api-call
suggests change to list structure in the createsurvey function?...wondering if other people have hit this issue?
thanks!
kevin