0

I want to consume SurveyMonkey API to get Question & answers in a .NET application, and i am suing The .Net wrapper. I can get general information about the survey like ( surveyId, number of questions...etc) but when i try to get collectors or questions or responses or any other obejct i get an error saying tht those objects are null. here is a piece of code of what i am trying to do

string apiKey = "key";
string token ="token";
var sm = new SurveyMonkeyApi(apiKey, token);
List<Survey> surveys = sm.GetSurveyList();

foreach(Survey s in surveys)
{
            //this link bellow is working fine
            MessageBox.Show("Survey Id:"+s.SurveyId); 

            List<Collector> collectorList = s.Collectors;
            //this line bellow give a System.NullReferenceException in "collectorList"
            foreach (Collector c in collectorList)
            {
             //Other instructions

            }
}

PS: i tried the PHP wrapper version and it was working fine.

GENE
  • 193
  • 1
  • 3
  • 11
  • I assume s.Collectors fetches collectors for that Survey, but what exact API call does it make? What does it get back? Does it even make a call or do you have to populate the collectors first then you can call `s.Collectors`? I need to see the .NET wrapper code to help debug, right now it looks like s.Collectors is Null. – General Kandalaft Oct 29 '16 at 20:33
  • yes s.Collectors is null for sure. i think the code source of the wrapper is available at [link](https://github.com/bcemmett/SurveyMonkeyApi) – GENE Oct 30 '16 at 17:07
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Enigmativity Oct 31 '16 at 05:27

1 Answers1

2

The GetSurveyList method of the wrapper calls the /surveys endpoint (https://developer.surveymonkey.net/api/v3/#surveys). Collections like Pages, Questions and Collectors will not be populated. If you want to get the associated collectors you'll need to make another API call. This will do it for you:

foreach (Survey s in surveys)
        {
            List<Collector> collectorList = sm.GetCollectorList(s.Id);
            foreach (Collector c in collectorList)
            {
                //Other instructions
            }
        }