Rest - Evidence - Questionnaires - Questions

From Views API Documentation
Jump to navigation Jump to search

Purpose

This API is used for creating, editing and deleting questionnaires from the Views system. It is not a way to submit questionnaire answer data. That is done via the other various sections.

Base URL

https://app.viewsapp.net/api/restful/evidence/questionnaires/<id>/questions

  • id - The is the id of the questionnaire.

Schema

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

Listing available Questions

curl --url <Base URL> -u<username>:<password> -H Content-Type:text/xml 
  • query - This is a text string to use to search for in the venues records

Questions are not searchable, and by default only the enabled questions are returned. If you want to get a complete list of questions, then you should use the following:

curl --url <Base URL>?allquestions=1 -u<username>:<password> -H Content-Type:text/xml 
<questions count="21">
    <question id="12">
        <QuestionID>12</QuestionID>
        <QuestionnaireID>3</QuestionnaireID>
        <Question>What?</Question>
        <valueListID>83</valueListID>
        <inputType>radio</inputType>
        <validation></validation>
        <category>What</category>
        <enabled>1</enabled>
        <order>0</order>
        <Created>2011-03-04 01:09:55</Created>
        <CreatedBy>ant</CreatedBy>
        <Updated>2011-03-04 01:09:55</Updated>
        <UpdatedBy>ant</UpdatedBy>
    </question>
...
    <question id="13">
        <QuestionID>13</QuestionID>
        <QuestionnaireID>3</QuestionnaireID>
        <Question>Date</Question>
        <valueListID>0</valueListID>
        <inputType>date</inputType>
        <validation>valid_date</validation>
        <category>What</category>
        <enabled>1</enabled>
        <order>0</order>
        <Created>2011-03-04 01:10:09</Created>
        <CreatedBy>ant</CreatedBy>
        <Updated>2011-03-04 01:10:09</Updated>
        <UpdatedBy>ant</UpdatedBy>
    </question>
</questions>


Fetching a Question's details

curl --url <Base URL>/<id> -u<username>:<password> -H Content-Type:text/xml
  • id - The id of the Question

This will return a single question in the format of:

<question id="12">
    <QuestionID>12</QuestionID>
    <QuestionnaireID>3</QuestionnaireID>
    <Question>What is the question</Question>
    <valueListID>83</valueListID>
    <inputType>radio</inputType>
    <validation></validation>
    <category>What</category>
    <enabled>1</enabled>
    <Created>2011-03-04 01:09:55</Created>
    <CreatedBy>ant</CreatedBy>
    <Updated>2011-03-04 01:09:55</Updated>
    <UpdatedBy>ant</UpdatedBy>
</question>


Creating a Single Question

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

<xml> should be in the following format:

<question>
    <Question>The question test...</Question>
    <inputType>text</inputType>
    <valueListID>0</valueListID>
    <validation/>
    <category>General</category>
</question>
  • Question - This should contain the wording for the question
  • inputTypes - This can be ne of the following:
    1. text
    2. textare
    3. date
    4. time
    5. number
    6. select
    7. selectother
    8. checkselect
    9. radio
  • valueListID - refers to a value list. This is only used with multiple choice inputTypes
  • category - This is the section title that the question should be grouped in

Validation Field

This can contain values similar to those found in the validation field for structure objects. However, here is a more specific explanation of the various optionsyou can place into this field:

  • oneOf - One of the questions are required to be answered.
  • required_if - The answer is required if condition met.
  • required - The answer is required.
  • valid_password - The answer field must contain a valid password as defined above
  • valid_postcode - The answer field must contain a valid postcode.
  • valid_email - The answer must contain a valid email address.
  • valid_emails - The answer must contain all valid email addresses.
  • valid_url - The answer must contain a valid URL.
  • real_url - The answer must contain a real URL.
  • valid_ip - The answer must contain a valid IP.
  • valid_date - The answer must contain a valid date.
  • min_length[n] - The answer must be at least n characters in length.
  • max_length[n] - The answer can not exceed n characters in length.
  • exact_length[n] - The answer must be exactly n characters in length.
  • alpha - The answer may only contain alphabetical characters.
  • alpha_numeric - The answer may only contain alpha-numeric characters.
  • alpha_dash - The answer may only contain alpha-numeric characters, underscores, and dashes.
  • alpha_dot - The answer field may only contain alpha-numeric characters, and dots.
  • numeric - The answer must contain only numbers.
  • is_numeric - The answer must contain only numeric characters.
  • is_numeric_non_zero - The answer must contain only numeric characters greater than zero.
  • integer - The answer must contain an integer.
  • is_natural - The answer must contain only positive numbers.
  • is_natural_no_zero - The answer must contain a number greater than zero.
  • range[min,max] - The answer is not within range.
  • unique_username - The answer value is already assigned, please try another
  • punique - The answer value already exists, within The, or another agency with the Programme


Note The following require further documentation (currently the wording isfor the error

  • matches - The answer does not match any other Answer.
  • nomatches - The answer matches the other answers.
  • matches1M - The answer value matches none of the other answer values.
  • nomatches1M - The answer value matches one of the other answer values.
  • matchesM1 - None of the answer values match this answer value.
  • nomatchesM1 - One of the answer values matches this answer field.
  • matchesMM - None of the answer values match any of this answer values.
  • nomatchesMM - Some of the answer values match some of this answer values.

Updating a Single Question

curl --url <Base URL>/<id> -u<username>:<password> -H Content-Type:text/xml -X PUT -d '<xml>'
  • id - The id of the question

The xml for updating a single question is exactly the same as the create xml.


Disable / Enable Questions

curl --url <Base URL>/<id>/enable -u<username>:<password> -H Content-Type:text/xml -X PUT -d '<xml>'
  • id - The id of the question


To disable a question you need to send the following xml:

<enable>0</enable>

or

<enable>false</enable>


To enable a question you need to send the following xml:

<enable>1</enable>

or

<enable>true</enable>


Creating / Updating Multiple Question

curl --url <Base URL> -u<username>:<password> -H Content-Type:text/xml -X [POST|PUT] -d '<xml>'
  • id - The id of a Questionnaire

This allows you to upload a complete questionnaire in one go

<questions>

    <question id="12">
        <Question>Update question 12</Question>
        <valueListID>83</valueListID>
        <inputType>radio</inputType>
        <validation></validation>
        <category>What</category>
    </question>
...
   <question>
        <Question>Add a new question</Question>
        <inputType>text</inputType>
        <valueListID>0</valueListID>
        <validation/>
        <category>General</category>
    </question>
</questions>

By specifying the id attribute for the question, it will update the question rather than create a new one.

It is recommended that you stip to using the PUT method for this, as in the future we make make POST and method to replace all the questions on a questionnaire