Я использовал API LSRC2 JSON/RPC 2.0 для подключения к Limesurvey и экспортировать завершенные опросы с Limesurvey версии 5.3.32 и C# в качестве языка программирования. Я использовал метод API export_responses, и все работало, как и ожидалось. Массив в результате, даже если есть опросы. Основные части кода: < /p>
private readonly JsonRpcClient client;
< /code>
var exportResponsesRequest = new JsonRpcRequest()
{
RequestId = ++requestId,
Method = "export_responses",
Parameters = new Dictionary
{
["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.
}
< /code>
The PostAsync function in JsonRcpClient class is as follow:
public async Task 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);
}
< /code>
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; }
}
< /code>
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.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ponses-api
Обновление Limesurvey до версии 6.6.5 создает проблемы с API export_responses ⇐ C#
Место общения программистов C#
1738222159
Anonymous
Я использовал API LSRC2 JSON/RPC 2.0 для подключения к Limesurvey и экспортировать завершенные опросы с Limesurvey версии 5.3.32 и C# в качестве языка программирования. Я использовал метод API export_responses, и все работало, как и ожидалось. Массив в результате, даже если есть опросы. Основные части кода: < /p>
private readonly JsonRpcClient client;
< /code>
var exportResponsesRequest = new JsonRpcRequest()
{
RequestId = ++requestId,
Method = "export_responses",
Parameters = new Dictionary
{
["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.
}
< /code>
The PostAsync function in JsonRcpClient class is as follow:
public async Task 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);
}
< /code>
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; }
}
< /code>
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.
Подробнее здесь: [url]https://stackoverflow.com/questions/79398168/limesurvey-upgrade-to-version-6-6-5-produces-issues-with-export-responses-api[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия