Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

RCApi: is there an easy way how to edit a response. [YES there is]

  • r0bis
  • r0bis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago - 1 year 7 months ago #241666 by r0bis
Dear All,
I have my own limesurvey installation in the cloud, updated with easy-update.

I need to use a survey to provide a demo for users to add new responses to the survey and then to immediately visualize it with R (using limer ).

Because users are better impressed by recent data, I am creating a method to bring sample data up to date. For example I make all submitdate fields to have x number of days added (i.e. add the number of days between max(submitdate) and now() minus one day) - to bring the dataset dates to yesterday.

I can do the process quite easily as far as getting the responses and changing the date in R.

However - is there an API call that I can employ to write the changed date back to the original response?

I am  aware that in surveys one usually would not want to change the data, but the use case is for a dummy dataset used strictly for demo purposes.

Many thanks,

Roberts

r0berts
Last edit: 1 year 7 months ago by r0bis.

Please Log in to join the conversation.

  • r0bis
  • r0bis's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 year 7 months ago - 1 year 7 months ago #241670 by r0bis
I think after a couple of hours I got the gist of it. The following will be documentation to remind myself how this is done.

So, requirements:
1. Limesurvey need to set "Allow multiple responses or update responses with one token:" to TRUE under Survey - Participant Settings otherwise you get the response "Error: Survey does not allow edit after completion."
2. Authenticate using your standard: 
Code:
skey <- get_session_key()
as described on  limer  github page
3. Then your update response method will be invoked via
Code:
call_limer
:
Code:
call_limer(method = "update_response",
           params = list(iSurveyID = limeSurveyNumber,
             aResponseData = aResponseData)
           )

where iSurveyID is your survey number and aResponseData you need to construct from your survey answers. If you have made a dataframe like
Code:
initData <- get_responses(limeSurveyNumber)
your fields that you can update as you like are the column names of your dataframe, with the exception of that actual question. In the dataframe you get the question code you assigned in LS interface as the column name. In your code you need to identify this field with the SGQA identifier.

So an example of things that you could update for a textual question would be:
Code:
aResponseData <- list("id" = 3, 
                      "submitdate" = "2028-04-23 10:04:34",
                      "lastpage" = 1, 
                      "startlanguage" = "en", 
                      "seed" = '111111222', 
                      "startdate" = "nodate", 
                      "datestamp" = "2023-03-23 10:04:34", 
                      "891422X157X1357" = "my new text response"
                      )


If your date fields (which you get when you ask the survey to store timings - that sets submitdate to complete responses and also makes startdate and datestamp fields) do not parse - the date will be set to 0000-00-00 00:00:00. 

The good news is - you can update as few fields in the response as you like. The only thing that must be there is the id (or token) field - so that LS knows which response to update. 
In my case I can construct a very simple response array (list) like this:
Code:
aResponseData <- list("id" = 3, "submitdate" = "2022-05-23 10:04:38")

The other fields that are mentioned (including the original answer) simply do not get updated (hopefully this could be confirmed by moderators).

r0berts
Last edit: 1 year 7 months ago by r0bis.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose