Welcome to the LimeSurvey Community Forum

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

add_participants API in VB.NET

  • accdev
  • accdev's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago #204529 by accdev
add_participants API in VB.NET was created by accdev
hi all,

I try to use c# sample from API manual and converted it to vb.net.
I call method add_participants as below code LS API just return me the value in parameter 'aParticipantData'
without any participant, token created. the error also returned nothing.

Anyone could advise on this ?


Sub Test
Dim Baseurl As String = "http://....../limesurvey/index.php?r=admin/remotecontrol"
Dim client As JsonRPCclient.JsonRPCclient = New JsonRPCclient.JsonRPCclient(Baseurl)
client.Method = "get_session_key"
client.Parameters.Add("username", "****")
client.Parameters.Add("password", "****")
client.Post()
Dim SessionKey As String = client.Response.result.ToString()
client.ClearParameters()

If client.Response.StatusCode = Net.HttpStatusCode.OK Then
client.Method = "add_participants"
client.Parameters.Add("sSessionKey", SessionKey)
client.Parameters.Add("iSurveyID", "751443")
client.Parameters.Add("aParticipantData", "[ {""email"":""me@example.com"",""lastname"":""Bond"",""firstname"":""James""},{""email"":""me2@example.com""} ]")
client.Post()
End If
debug.pring(client.Response.result.ToString())
End Sub


Thanks in advance,
Accdev
The topic has been locked.
More
3 years 1 month ago #212298 by frederic.tahir
Replied by frederic.tahir on topic add_participants API in VB.NET
Hello Accdev,
Do you find a solution ? Coud you post your code (c# or vb.net) to add participants ?
Thks
The topic has been locked.
More
2 years 11 months ago #214743 by alkiviadis
Replied by alkiviadis on topic add_participants API in VB.NET
did you find any solution?
The topic has been locked.
More
2 years 11 months ago #214750 by frederic.tahir
Replied by frederic.tahir on topic add_participants API in VB.NET
Yes, here under my code in C# to add and invite participants :

public string InjectParticipant(string email, string firstname, string lastname, string attribute_1, string attribute_2, string attribute_3, string attribute_4)
{


string Baseurl = "http://localhost/index.php/admin/remotecontrol";

JsonRPCclient client = new JsonRPCclient(Baseurl);
client.Method = "get_session_key";
client.Parameters.Add("username", "admin");
client.Parameters.Add("password", "XXXXXX");
client.Post();
string SessionKey = client.Response.result.ToString();
client.ClearParameters();

var RegisteredUsers = new List<Person>();
RegisteredUsers.Add(new Person() { email = email, firstname = firstname, lastname = lastname, attribute_1 = attribute_1, attribute_2 = attribute_2, attribute_3 = attribute_3, attribute_4 = attribute_4 });

client.Method = "add_participants";
client.Parameters.Add("sSessionKey", SessionKey);
client.Parameters.Add("iSurveyID", SurveyID);
client.Parameters.Add("aParticipantData", Newtonsoft.Json.Linq.JToken.FromObject(RegisteredUsers));
client.Parameters.Add("bCreateToken", true);
client.Post();

var ParticipantID = JsonConvert.DeserializeObject<List<YourJsonClass>>(client.Response.result.ToString()).Select(o => o.tid).ToList();
var ParticipantToken = JsonConvert.DeserializeObject<List<YourJsonClass>>(client.Response.result.ToString()).Select(o => o.token).ToList();

client.ClearParameters();



client.Method = "invite_participants";
client.Parameters.Add("sSessionKey", SessionKey);
client.Parameters.Add("iSurveyID", SurveyID);
client.Parameters.Add("aTokenIds", Newtonsoft.Json.Linq.JToken.FromObject(ParticipantID));
client.Parameters.Add("bEmail", true);
client.Post();
client.ClearParameters();


return ParticipantToken[0].ToString();


}
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose