Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Lime Survey Upgrade and RPC 2.0 API

  • jambouz
  • jambouz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 35 minutes ago #268817 by jambouz
Lime Survey Upgrade and RPC 2.0 API was created by jambouz
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.3.32 and 6.6.5
Own server or LimeSurvey hosting: Own Server Hosting
Survey theme/template: custom
==================
Hello,

I used LSRC2 JSON/RPC 2.0 API to connect to LimeSurvey server and export the participants responses of completed surveys with LimeSurvey version 5.3.32 using code in C# 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 returned an empty result even if there were surveys completed (Postman return the correct values).

The Programming Language Used: C#
The LimeSurvey Database: SQLServer

Here are the main parts of the code:
Code:
private readonly JsonRpcClient client;
Code:
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 JsonRpcClient class is as follow:
Code:
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 JsonRpcResponse is as follow:
Code:
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 had the correct results with the same configuration using Postman.

I tried all possible changes that I found online, but unfortunately  I couldn't resolve the issue.
Could you please help me figure out what the issue is.

Thanks for your answer.
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • jambouz
  • jambouz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 days 23 hours ago #268924 by jambouz
Replied by jambouz on topic Lime Survey Upgrade and RPC 2.0 API
Hello,

I wait for an answer. Please help me answer this issue as the project using it is very important for my organization.

Here are the snippets of the code that were not clearly displayed in the previous message.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; } }
Please help me resolve the issue.
Thanks a lot for your answer.

 

Please Log in to join the conversation.

  • jambouz
  • jambouz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 days 22 hours ago #268926 by jambouz
Replied by jambouz on topic Lime Survey Upgrade and RPC 2.0 API
Hello,

I have some formatting issue posting my messages.
Here are all important sections entered manually. Please help me resolve the issue, it is very important for my project

private readonly JsonRpcClient client;

var exportResponsesRequest = new JsonRequest()
{   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 base 64, it likely contains and error message.
}


The PostAsync function in JsonRpcClient class is as follow:

public async Task<JsonRpcResponse> PostAsync(JsonRpcRequest requestObject)
{
   var httpClient = new HttpClient();
   string requestJson = JsonSerializer(requestObject);
   var strintContent = 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 JsonRpcResponse 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;}
}

Let me know if you need more details.
Thanks.

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose