Rest - Evidence - Questionnaires - Answers

From Views API Documentation
Jump to navigation Jump to search

Purpose

Used for submitting answer sets to questionnaires against participants and for retrieving the details of answered questionnaires that have been submitted. It is the preferred solution to use the contextualised version of this API.

Base URL

https://app.viewsapp.net/api/restful/evidence/questionnaires/<qid>/answers

  • qid - This is the questionnaire id

Schema

https://app.viewsapp.net/api/restful/evidence/questionnaires/answers/answerset-schema(.xml|.json|.xsd)

https://app.viewsapp.net/api/restful/evidence/questionnaires/answers/answers-schema(.xml|.json|.xsd)

Fetching a list of answer sets

The default call will return a list of questionnaires (answer sets) that have been recorded against the questionnaire

curl --url <Base URL> -u<username>:<password> -H Content-Type:text/xml

This will return data similar to the following:

<answersets count="2">
    <answerset id="1" questionnaireid="14">
        <EntityType>Person</EntityType>
        <EntityID>1</EntityID>
        <Date>2012-07-31T10:00:00</Date>
        <QuestionnaireID>14</QuestionnaireID>
        <AnswerSetID>1</AnswerSetID>
        <Questionnaire>Impact</Questionnaire>
    </answerset>
    <answerset id="6" questionnaireid="14">
        <EntityType>Person</EntityType>
        <EntityID>1</EntityID>
        <Date>2012-05-02T09:10:00</Date>
        <QuestionnaireID>14</QuestionnaireID>
        <AnswerSetID>6</AnswerSetID>
        <Questionnaire>Impact</Questionnaire>
    </answerset>
</answersets>

The results are order by the most recent first. This means to get the latest version of a questionnaire, you would only need to fetch the first result.

Optionally, you can can append the ?include-answers parameter to include all the actual answer data alongside the answer set details. This will convert the <answerset> object to something more like that described below. This is not recommended due to the volume of data that it could return

Fetching the answers of a given questionnaire answerset

curl --url <Base URL>/<setId> -u<username>:<password> -H Content-Type:text/xml
  • setId - This is the id of the Answers Set you want to retrieve

It's will return something along the lines of

<answerset questionaireid="14" id="1">
    <EntityType>Person</EntityType>
    <EntityID>1</EntityID>
    <TargetType/>
    <TargetID>0</TargetID>
    <Date>2012-07-31T10:00:00</Date>
    <answers count="9">
        <answer id="78">
            <QuestionID>78</QuestionID>
            <Answer>Fully Agree</Answer>
        </answer>
        <answer id="79">
            <QuestionID>79</QuestionID>
            <Answer>Truly Agree</Answer>
        </answer>
        <answer id="80">
            <QuestionID>80</QuestionID>
            <Answer>Agree</Answer>
        </answer>
        ...
    </answers>
</answerset>


Fetching a single answer from a questionnaire

curl --url <Base URL>/<setId>/<questionId> -u<username>:<password> -H Content-Type:text/xml
  • setId - This is the id of the Answers Set you want to retrieve
  • questionId - This is the id of the question you want the answer for
<answer id="78">
    <QuestionnaireID>14</QuestionnaireID>
    <AnswerSetID>1</AnswerSetID>
    <QuestionID>78</QuestionID>
    <Answer>Fully Agree</Answer>
</answer>


Creating a new Answer Set

curl --url <Base URL> -u<username>:<password> -H Content-Type:text/xml -X POST -d '<xml>'

To submit a new set of answers against a questionnaire, you should send data in the following structure:

<answers>
    <Date>2012-07-31T10:00:00</Date>
    <answer id="78">
      <QuestionID>78</QuestionID>
      <Answer>Fully Agree</Answer>
    </answer>
    <answer id="79">
      <QuestionID>79</QuestionID>
      <Answer>Truly Agree</Answer>
    </answer>
    ...
</answers>

Note: If you specify the attribute id then you do not need to specify the <QuestionID> entity.

You can also relate the questionnaire to a Session (and SessionGroup) by specifying the <TargetType> and <TargetID> entities

<answers>
    <TargetType>Session</TargetType>
    <TargetID>214</TargetID>
    <Date>2012-07-31T10:00:00</Date>
    <answer id="78">
      <QuestionID>78</QuestionID>
      <Answer>Fully Agree</Answer>
    </answer>
    ....
</answers>

You can also omit the <Date> entity. If you do this, then the current system date/time will be used.


Updating an existing Answer Set

curl --url <Base URL>/<setid> -u<username>:<password> -H Content-Type:text/xml -X PUT -d '<xml>'

When updating the answers in an answer set, you should use the same structure as when creating a new answer set. However, if you specify the entities TargetType> and TargetID> they will be ignored.