limesurveyrc2api icon indicating copy to clipboard operation
limesurveyrc2api copied to clipboard

Wrong key in list_surveys() request

Open maxpejs opened this issue 2 years ago • 1 comments

method _Survey.list_surveys() uses key 'iSurveyID' to get survey list. According to REST-API, it shoud be 'sUsername'

Tested with: limesurveyrc2ap master-commit: 866cf62 LimeSurvey Community Edition Version 6.4.7

maxpejs avatar Feb 22 '24 08:02 maxpejs

Workaround is to overwrite the function.

def list_surveys(api, username=None):
    from collections import OrderedDict
    method = "list_surveys"
    params = OrderedDict([
        ("sSessionKey", api.session_key),
        ("sUsername", username or api.username)
    ])
    response = api.query(method=method, params=params)
    response_type = type(response)
    if response_type is dict and "status" in response:
        status = response["status"]
        error_messages = [
            "Invalid user",
            "No surveys found",
            "Invalid session key"
        ]
        for message in error_messages:
            if status == message:
                raise LimeSurveyError(method, status)
            else:
                assert response_type is list
    return response

api.survey.list_surveys = list_surveys

# from the example
result = api.survey.list_surveys(api)

felixdollack avatar Jan 28 '25 01:01 felixdollack