lindsay-stevens/limesurveyrc2api

Poblem importing surveys

Closed this issue · 1 comments

Well I was trying to import surveys using .txt files and I had a huge problem, it broke lime.

After a while I tought I should share my solution. Well the problem is when you import a survey file it needs to be base64 encoded, and then python writes on the data to send to the server "b'yourEncodedText'", instead of "yourEncodedText". Also survey id and survey title are not mandatory arguments while in the api code it is. So I made this changes in the function import_survey:

def import_survey(self, idata, title=None, sid=None, type='lss'):
data = """{ "id": 1,
"method": "import_survey",
"params": { "sSessionKey": "%s",
"sImportData": "%s",
"sImportDataType": "%s",
"sNewSurveyName": "%s",
"DestSurveyID": %s } }"""
% (self.session_key, idata.decode('utf-8'), type, title if title else '', str(sid) if sid else '""')
return self._getJSON(data)['result']

Thanks but there's no import_survey in this repo, I guess you meant this for one of the forks?