Skip to content

Questionnaires API

amplifi edited this page Jun 29, 2017 · 1 revision

Get questionnaire of a project

Request

GET /organizations/{organisation-slug}/projects/{project-slug}/questionnaire/
Content-Type: application/json
Authorization: Token 1398dojk9sd8jf9hsd89hd

Successful response

HTTP/1.1 200 OK
Content-Type: application/json

{
    "id": "mgc3ert5z7xw3zk6pti5s37p",
    "name": "xls-form",
    "title": "Question types",
    "id_string": "question_types",
    "xls_form": "https://amazonaws.com/some-bucket/…",
    "version": 1,
    "questions": [{
        "id": "dajqf38zcwz7kk9pikdkf4km",
        "name": "intro",
        "label": "This form showcases the different question types available in XLSForm.",
        "type": "NO",
        "required": false,
        "constraint": null
    }],
    "question_groups": [{
        "id": "7s77sskc4nqkwk768vaey6c2",
        "name": "meta",
        "label": null,
        "questions": [{
            "id": "gme7zwxru92q36v64jknf4ik",
            "name": "instanceID",
            "label": null,
            "type": "CA",
            "required": false,
            "constraint": null
        }]
    }, {
        "id": "bh8yp4jfiqvueutfm6aywfk9",
        "name": "select_questions",
        "label": "Basic Select question types",
        "questions": [{
            "id": "73xpfs6c3jbwbywtc6zrgqj5",
            "name": "my_select1",
            "label": "Select one question",
            "type": "S1",
            "required": false,
            "constraint": null,
            "options": [{
                "id": "cm82ftkb55kvjdgdnr6xaptu",
                "name": "2",
                "label": "option 2"
            }, {
                "id": "dcfisbmjui5indyutdmynhgn",
                "name": "1",
                "label": "option 1"
            }]
        }]
    }]
}

Errors

Organisation or project where not found.

HTTP/1.1 404 Not found
Content-Type: application/json
{
  "error": "Project does not exist"
}

No questionnaire assigned to the project

HTTP/1.1 404 Not found
Content-Type: application/json
{
  "error": "Questionnaire does not exist"
}

User is not allowed to view the questionnaire

HTTP/1.1 403 Permission denied
Content-Type: application/json
{
  "error": "You do not have permission to perform this action."
}

Create or update questionnaire of a project

Request

PUT /organizations/{organisation-slug}/projects/{project-slug}/questionnaire/
Content-Type: application/json
Authorization: Token 1398dojk9sd8jf9hsd89hd

{
    "xls_form": "https://amazonaws.com/some-bucket/…"
}

xls_form is an URL pointing to a XLS file that has been uploaded to AWS before. The file is downloaded and processed on server-side.

Response

HTTP/1.1 201 Created
Content-Type: application/json

{
    "id": "mgc3ert5z7xw3zk6pti5s37p",
    "name": "xls-form",
    "title": "Question types",
    "id_string": "question_types",
    "xls_form": "https://amazonaws.com/some-bucket/…",
    "version": 1,
    "questions": [{
        "id": "dajqf38zcwz7kk9pikdkf4km",
        "name": "intro",
        "label": "This form showcases the different question types available in XLSForm.",
        "type": "NO",
        "required": false,
        "constraint": null
    }],
    "question_groups": [{
        "id": "7s77sskc4nqkwk768vaey6c2",
        "name": "meta",
        "label": null,
        "questions": [{
            "id": "gme7zwxru92q36v64jknf4ik",
            "name": "instanceID",
            "label": null,
            "type": "CA",
            "required": false,
            "constraint": null
        }]
    }, {
        "id": "bh8yp4jfiqvueutfm6aywfk9",
        "name": "select_questions",
        "label": "Basic Select question types",
        "questions": [{
            "id": "73xpfs6c3jbwbywtc6zrgqj5",
            "name": "my_select1",
            "label": "Select one question",
            "type": "S1",
            "required": false,
            "constraint": null,
            "options": [{
                "id": "cm82ftkb55kvjdgdnr6xaptu",
                "name": "2",
                "label": "option 2"
            }, {
                "id": "dcfisbmjui5indyutdmynhgn",
                "name": "1",
                "label": "option 1"
            }]
        }]
    }]
}

Errors

Organisation or project where not found.

HTTP/1.1 404 Not found
Content-Type: application/json
{
  "error": "Project does not exist"
}

User is not allowed to create or update the questionnaire

HTTP/1.1 404 Permission denied
Content-Type: application/json
{
  "error": "You do not have permission to perform this action."
}

An invalid XLSForm has been uploaded.

HTTP/1.1 400 Bad request
Content-Type: application/json
{
  "xls_form": [
        "'interger' is not an accepted question type"
  ]
}
Clone this wiki locally