1

I'm trying to modify a single response through Remote Control using request promise native with a Node Server, so far all API calls have been successful, unfortunately "update_response" has not. this is what I've got:

var options = {
    uri: "http://localhost/admin/remotecontrol",
    method: "POST",
    body: {
      method:'update_response', 
      params:[sessionkey,surveyid,{ id: 5, token: "aValidToken", aValidColumnName: "a perfectly normal string" }],
      id:1
    },
    json: true
};

request(options).then((body) => {
    console.log(body.result);
}).catch((err) => {
    res.send(err);
});

The LimeSurvey API docummentation is not quite clear as to what structure the third parameter should have (https://api.limesurvey.org/classes/remotecontrol_handle.html#method_update_response), funnily enough if I only pass { id: 5, token: "aValidToken" } it does work (outputs "true"), with a key value pair though I'm getting:

Error: Invalid Column names supplied: aValidColumnName

Has anyone had success with this?

DosZero
  • 11
  • 1

2 Answers2

1

The column names are the question or sub-question IDs - https://manual.limesurvey.org/SGQA_identifier/en

I would think that the third parameter is an array of question/sub-question IDs and answers.

{'123':'A1', '124':'A3', '128':'Some text input...'}
tpartner
  • 421
  • 2
  • 5
1

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:

  1. 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."
  2. Authenticate using your standard: skey <- get_session_key() as described on limer github page
  3. 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.

r0berts
  • 842
  • 1
  • 13
  • 27