none
How to retrieve sharepoint survey question and answer in REST api?

All replies

  • Hi,

    I have created a survey list named “List_survey”, added question “Question01” with choices “Choice01”/”Choice02”/”Choice03”. Then I responded “Question01” with “Choice02”.

    Here is my Rest API URL to get questions and responses: /_api/web/lists/getbytitle('List_survey')/items.

    The result:

    Thanks,

    Dean Wang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, February 17, 2017 3:01 AM
    Moderator
  • Hi Dean,

    Thank you for your reply. This code will return only answer it won't return question as well. please find the below code for your reference. It will return the answer based on the question

    For ex: var url="https://site/_api/Web/Lists/getByTitle('Survey%20List')/items";

        $.ajax({
            url: url,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {
                for(i=0;i<data.d.results.length;i++)
                    {
                        $("#divSurvey").append(data.d.results[i].Question1);
                    }                        
            },
            error: function (data) {
              // failure(data);
            }
        });    

    Answer: "Choice1"

    but I need to get both question and answer for some transformation logic.

    For ex: Question1 : Choice1

     var url = "https://sites//_api/Web/Lists/getByTitle('Survey%20List')/fields?$filter=(CanBeDeleted%20eq%20true)

    Above query is returning question alone. But I need to retrieve both question and answer. Please help to get. 

    Regards

    Manikandan C



    Friday, February 17, 2017 5:56 AM
  • Hi,

    You can use the following way to retrieve json both key and value:

    $.each(result[0], function(key, value){

        console.log(key, value);

    });

    Thanks,

    Dean Wang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, March 13, 2017 7:50 AM
    Moderator