Rest - Contacts - Staff - Questionnaires

From Views API Documentation
Revision as of 13:01, 26 February 2016 by Wikiadmin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Purpose

Used for submitting answer sets to questionnaires against staff records and for retrieving the details of answered questionnaires that have been submitted against a participant. This is only really a filtered version of the Questionnaires - Answers API

Base URL

https://app.viewsapp.net/api/restful/contacts/staff records/<id>/questionnaires

  • id - This is the participant id

Schema

For details of the schemas, please refer to Rest - Evidence - Questionnaires - Answers


Fetching a list of answer sets

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

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

This will return data similar to the following:

<answersets count="7">
    <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="4" questionnaireid="5">
        <EntityType>Person</EntityType>
        <EntityID>1</EntityID>
        <Date>2012-05-04T10:11:00</Date>
        <QuestionnaireID>14</QuestionnaireID>
        <AnswerSetID>4</AnswerSetID>
        <Questionnaire>Interests</Questionnaire>
    </answerset>
    ...
</answersets>

If you are only interested in a particular questionnaire, you should us the following:

curl --url <Base URL>/<questionnairId> -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.


Fetching the answers of a given questionnaire

curl --url <Base URL>/<questionnairId>/<setId> -u<username>:<password> -H Content-Type:text/xml
  • questionnaireId - This is the id of the questionnaire
  • 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>/<questionnairId>/<setId>/<questionId> -u<username>:<password> -H Content-Type:text/xml
  • questionnaireId - This is the id of the questionnaire
  • 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>/<questionnairId> -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>/<questionnairId>/<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.