Je n'ai pas accès à quoi que ce soit sur le serveur ou se situe Limesurvey. On m'a juste fourni un compte avec les droits d'admin pour que je puisse appeler l'API.
Pour plus d'information sur mon code, voici ma fonction pour récupérer et sauvegarder dans un fichier les participants
Code:
public void GetParticipantJsonFile(string surveyKey)
{
var attribute = new string[] { "attribute_1", "attribute_2" };
this.Client.ClearParameters();
this.Client.Method = "list_participants";
this.Client.Parameters.Add("ssessionkey", this.SessionKey);
this.Client.Parameters.Add("isurveyid", surveyKey);
this.Client.Parameters.Add("aAttributes", JArray.FromObject(attribute));
this.Client.Parameters.Add("bUnused", false);
this.Client.Post();
//save in file
File.WriteAllBytes(@"C:\Users\xxxx\Desktop\test.json", this.Client.Response.GetFileBlob());
}
Et celui qui permet d'appeler l'API
Code:
public JsonRPCResponse Post()
{
JObject jobject = new JObject();
jobject.Add(new JProperty("jsonrpc", "2.0"));
jobject.Add(new JProperty("id", ++id));
jobject.Add(new JProperty("method", Method));
jobject.Add(new JProperty("params", Parameters));
string PostData = JsonConvert.SerializeObject(jobject);
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(PostData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.ContentType = "application/json";
request.KeepAlive = true;
request.ContentLength = bytes.Length;
Stream writeStream = request.GetRequestStream();
writeStream.Write(bytes, 0, bytes.Length);
writeStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
Response = new JsonRPCResponse();
Response = JsonConvert.DeserializeObject<JsonRPCResponse>(readStream.ReadToEnd());
Response.StatusCode = response.StatusCode;
return Response;
}
Je me retrouve donc avec une requête de ce type
Code:
{
"jsonrpc": "2.0",
"id": 2,
"method": "list_participants",
"params": {
"ssessionkey": "xxx",
"isurveyid": "xxx",
"aAttributes": [
"attribute_1",
"attribute_2"
],
"bUnused": false
}
}
et comme résultat une liste d'object comme celui-ci
Code:
{
"tid": "xxx",
"token": "xxx",
"participant_info": {
"firstname": "xxxx",
"lastname": "xxx",
"email": "xxx@xxx.x"
}
}