I had the same question and information that I could find was not readily available in 2023. Hence I am giving answer to 5 years old question as for a newcomer it is difficult to understand the answer given by @tpartner. I use R and the limer package, but doing the same would be pretty similar in other languages.
Limesurvey API documentation is sparse:
- Update a response in a given survey.
update_response(string $sSessionKey,integer $iSurveyID,array $aResponseData): array|boolean
- Routine supports only single response updates. Response to update will be identified either by the response id, or the token if response id is missing. Routine is only applicable for active surveys with alloweditaftercompletion = Y.
Answer:
- In Limesurvey you 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."
- Authenticate using your standard:
skey <- get_session_key()
as described on limer github page
- Then your update response method will be invoked via call_limer:
call_limer(method = "update_response",
params = list(iSurveyID = limeSurveyNumber,
aResponseData = aResponseData)
)
where iSurveyID
is your survey numeric ID and aResponseData
is an array you need to construct for your survey answers. If you have made a dataframe as in mydataFrame <- get_responses(limeSurveyNumber)
your fields that you can update whatever way you like are the column names of your dataframe, with the exception of the survey question. In the dataframe you have the coulmn name set to the question code you assigned in LS interface. In your code you must to identify this field with the SGQA identifier.
So an example of how one could create an array (list in R) to be used to update a single textual question would be:
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. Timings set submitdate
field to time when the response was completed and also creates startdate
and datestamp
fields) do not parse - the date will be set to 0000-00-00 00:00:00
.
The good thing is - you can update as few fields in the response as you like. The only thing that must be there is the id field - so that LS knows which response to update.
In my case when I need to alter the submitdate
for a demo data set, I can construct a very simple response array (list) like this:
aResponseData <- list("id" = 3, "submitdate" = "2022-05-23 10:04:38")
The other fields simply do not get updated.