Welcome to the LimeSurvey Community Forum

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

limesurvey api add_participants method cannot add participant

  • cetin.sahin
  • cetin.sahin's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 7 months ago #231188 by cetin.sahin
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Community Edition
Version 5.3.26+220720
Own server or LimeSurvey hosting: Own server
Survey theme/template: fruity
==================
(Write here your question/remark)
I call limesurvey api add_participants  method  with c#.
Respose message is equal to request 
there is no error. But i can't see adding participant in my survey in portal.
Can you explain how can i call add_participant method step by step via JSONRPC
My c# code : 
                client.Method = "add_participants";
                client.Parameters.Add("sSessionKey", SessionKey);

                client.Parameters.Add("iSurveyID", sid);

       
                var Listeklejson = JsonConvert.SerializeObject(surveyParticipantList);


                client.Parameters.Add("aParticipantData", Base64Encode(Listeklejson));

                client.Parameters.Add("bCreateToken", false);
;
                client.Post();

 

Please Log in to join the conversation.

  • cetin.sahin
  • cetin.sahin's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 7 months ago #231189 by cetin.sahin
List<aParticipantData> Listekle = new List<aParticipantData>();
aParticipantData ekle = new aParticipantData { email = "test@test.com", lastname = "test", firstname = "test", language = "tr" , emailstatus = "OK" };
Listekle.Add(ekle);

Please Log in to join the conversation.

More
1 year 6 months ago #231901 by jared.kail
Hi. One thing that tripped me up is that you have to send an array of participants to add_participants and not a single participant. If you are only adding one participant, you still need to send it as a single element of an array. I'm a php coder so my apologies about the syntax difference, but you have to pass this:
Code:
[["email"=>"someone@gmail.com", "lastname"=>"Someone", "firstname"=>"Cool"]]

and NOT this:
Code:
["email"=>"someone@gmail.com", "lastname"=>"Someone", "firstname"=>"Cool"]

That may not be your issue, but thought I'd throw in what tripped me up just in case.

Please Log in to join the conversation.

More
11 months 3 weeks ago - 11 months 3 weeks ago #241904 by FherStk
Same issue here.

This is my code:
var data = "[{'email':'me@example.com','lastname':'Bond','firstname':'James', 'language': 'en', 'emailstatus': 'OK'}]";

this.Client.Method = "add_participants";
this.Client.Parameters.Add("sSessionKey", this.SessionKey);
this.Client.Parameters.Add("iSurveyID", surveyID);
this.Client.Parameters.Add("aParticipantData", data);

this.Client.Post();


I get as response just the same json i sent, but no participant is beeing created within the survey... I tried a lot of combinations (suing base64, setting up the token, etc) but nothing works.

Please, I need help :(

Thanks,
Fer
Last edit: 11 months 3 weeks ago by FherStk. Reason: Changed \" for ' in order to clarify

Please Log in to join the conversation.

More
11 months 3 weeks ago - 11 months 3 weeks ago #241914 by jared.kail
Try this instead:
Code:
var data = "[[{'email':'me@example.com','lastname':'Bond','firstname':'James', 'language': 'en', 'emailstatus': 'OK'}]]";
Last edit: 11 months 3 weeks ago by jared.kail.

Please Log in to join the conversation.

More
11 months 3 weeks ago #241916 by FherStk
I tried this before, but it doesn't work either, the participants list remains empty, and the API response is just the same JSON I sent.

Please Log in to join the conversation.

More
11 months 3 weeks ago #241929 by FherStk
Solved!

The string containing the json data must be parsed:

var data = "[{'email':'me@example.com','lastname':'Bond','firstname':'James', 'language': 'en', 'emailstatus': 'OK'}]";

WRONG:
this.Client.Parameters.Add("aParticipantData", data);

CORRECT:
this.Client.Parameters.Add("aParticipantData", JArray.Parse(data));


Thanks to everyone for your help :)
Fher
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • cetin.sahin
  • cetin.sahin's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
11 months 3 weeks ago #241932 by cetin.sahin
I tried all different method . and then i added participants via db connection.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose