How to map Questions and Answers in surveys in SharePoint Rest API?

eggy mcegg 120 Reputation points
2024-08-01T15:07:09.1733333+00:00

I have a requirement where I need to get the full question and the full answer to a survey in SharePoint.

We can get the list item of the survey answer which gives us something like


{...
"Single_x0020_line_x0020_text_x00": "single line 1",
 "Multiple_x0020_line_x0020_text_x": "multiple line 2",
 "A_x0028_n_x0029__x0020________x0": "C. independent"
...}		

The problem with this is the full answer is not there. So I then have to get the /Fields on a list which use the EntityPropertyName to match the full questions between the answer and the Fields.

{
"value": [
{
...
"EntityPropertyName": "Single_x0020_line_x0020_text_x00",
"Title": "Single line text question number 1?"
...
}
]
}

As you can see this gets complicated quite quickly to map these together.

Is there an easier way I can do this? I'm relatively new to SharePoint rest api so apologies if i missed something out.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,059 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 36,256 Reputation points Microsoft Vendor
    2024-08-02T02:50:38.4066667+00:00

    Hi @eggy mcegg,

    You could filter fields by SPField.CanBeDeleted property in order to get the list of questions from a Survey List

    How to get the list of questions from a Survey List via REST API

    /_api/Web/Lists/getByTitle('Survey')/fields?$filter=(CanBeDeleted eq true)
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.