admin管理员组

文章数量:1317915

I used LSRC2 JSON/RPC 2.0 API to connect to LimeSurvey and export the completed Surveys with LimeSurvey version 5.3.32 and C# as a programming language. I used the export_responses API method and Everything was working as expected.

Recently I upgraded to LimeSurvey version 6.6.5, and the same code that expected to return values with export_responses API always return an empty array as a result even if there are surveys completed.

The Programming Language is C# The LimeSurvey Database is SQLServer

Here are the main parts of the code:

private readonly JsonRpcClient client;
var exportResponsesRequest = new JsonRpcRequest()
{
    RequestId = ++requestId,
    Method = "export_responses",
    Parameters = new Dictionary<string, object>
    {
        ["sSessionKey"] = sessionKey,
        ["iSurveyID"] = surveyId,
        ["sDocumentType"] = "json",
        ["sLanguageCode"] = language,
        ["sCompletionStatus"] = completionStatus,
        ["sHeadingType"] = headingType,
        ["sResponseType"] = responseType,
        ["iFromResponseID"] = fromResponseID,
        ["iToResponseID"] = toResponseID
    },
};
var response = await client.PostAsync(exportResponsesRequest);
try
{
    return DecodeBase64(response.Result?.ToString());
}
catch
{
    // If string isn't base64, it likely contains an error message.
}

The PostAsync function in JsonRcpClient class is as follow:

public async Task<JsonRpcResponse> PostAsync(JsonRpcRequest requestObject)
 {
     var httpClient = new HttpClient();
     string requestJson = JsonSerializer.Serialize(requestObject);
     var stringContent = new StringContent(requestJson, Encoding.UTF8, "application/json");
     var httpResponse = await httpClient.PostAsync(url, stringContent);
     var resultString = await httpResponse.Content.ReadAsStringAsync();
     return ProcessResponseObject(resultString, httpResponse.StatusCode, requestObject);
 }

And the class JsonRcpResponse is as follow:

public class JsonRpcResponse
 {
     [JsonPropertyName("id")]
     public int Id { get; set; }

     [JsonPropertyName("result")]
     public object Result { get; set; }

     [JsonPropertyName("error")]
     public string Error { get; set; }

     public HttpStatusCode StatusCode { get; set; }
 }

Notice that I have the correct result with the same configuration running on postman.

I tried all possible changes that I found online, but I couldn’t resolve the issue.

I tried Upgrading LimeSurvey from version 5.3.32 to version 6.6.5 and the code that calls LimeSurvey API stopped working. I stepped through the code and I found out that the export_responses API always returns an empty array as a JSON response, even if there were completed surveys to export. The same method in Postman returned the correct array of responses using LimeSurvey version 6.6.5.

When reverting the LimeSurvey to the previous version (5.3.32) without any change of the code, the API resumed working as expected.

本文标签: cLimeSurvey upgrade to version 665 produces issues with exportresponses APIStack Overflow