Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

API: Pages

Joshua Kalpin edited this page Mar 14, 2016 · 7 revisions

Page

A Page represents a screen within the Sana mobile app. It encapsulates a series of Element objects and has a ShowIf that represents the conditions that it will be shown.

Path

/api/pages

Permissions

Only the user that owns the procedure that this page is a part of may access or modify it.

Fields

Field Name Type Required? Default Value Read Only? Description
id int Yes Yes The unique id for this page.
procedure Procedure Yes No The procedure that this page belongs to.
display_index int Yes No Represents where the page is located from 1..n within the procedure.
show_if list<ShowIf> No No The condition for displaying this page. You can have a maximum of one of these per page.
elements list<Element> No No The elements that make up this page. These are automatically added when creating an element.
created datetime Yes Yes The time that this object was created. This value is auto-generated
last_modified datetime Yes Yes The last time that this object was updated. This value is auto-generated.

Creating

To create a page POST to /api/pages.

Status Codes

201: Object Created Successfully

400: Bad value in the request body. Check the response for errors

401: Invalid Request Token

Example Request

POST /api/pages
Host: sanaprotocolbuilder.me
Authorization: Token <token>
{
  "procedure":8,
  "display_index":0
}

Example Response

{
  "id":7,
  "display_index":0,
  "procedure":8,
  "elements":[],
  "last_modified":"2016-03-06T23:33:32.595421Z",
  "created":"2016-03-06T23:33:32.595488Z",
  "show_if":[]
}

Updating

To update a page PUT to /api/pages/{id}, where id is the id of the page. You only need to send the fields that are to be updated in the body of the request. Sending up other fields that are not modified, will not do anything.

Status Codes

200: Object Updated Successfully

400: Bad value in the request body. Check the response for errors

401: Invalid Request Token

404: Page does not exist

Example Request

PUT /api/pages/7
Host: sanaprotocolbuilder.me
Authorization: Token <token>
{
  "display_index":1
}

Example Response

{
  "id":7,
  "display_index":1,
  "procedure":8,
  "elements":[],
  "last_modified":"2016-03-06T23:33:32.595421Z",
  "created":"2016-03-06T23:33:32.595488Z",
  "show_if":[]
}

Bulk Updates

To update multiple pages, even with partial data, send a PATCH request to /api/pages/partial_bulk_update.

Status Codes

200: Object successfully updated

400: Invalid or missing data in request body

Example Request

PATCH /api/pages/partial_bulk_update
Host: sanaprotocolbuilder.me
Authorization: Token <token>
[
  {
    "id": 2,
    "display_index": 1
  },
  {
    "id": 3,
    "display_index": 2
  }
]

Example Response

[
  {
    "id":2,
    "display_index":1,
    "procedure":8,
    "elements":[],
    "last_modified":"2016-03-06T23:33:32.595421Z",
    "created":"2016-03-06T23:33:32.595488Z",
    "show_if":[]
  },
  {
    "id":3,
    "display_index":2,
    "procedure":12,
    "elements":[],
    "last_modified":"2016-03-06T23:35:32.595421Z",
    "created":"2016-03-06T23:34:32.595488Z",
    "show_if":[]
  }
]

Deleting

To delete a page send a DELETE request to /api/pages/{id} where the id is the id of the page to be deleted.

Status Codes

203: Object successfully deleted

401: Invalid Request Token

404: Page does not exist

Example Request

DELETE /api/pages/7
Host: sanaprotocolbuilder.me
Authorization: Token <token>

Example Response

No response body

Getting All

To get all pages that you own GET to /api/pages.

Status Codes

200: Success

401: Invalid Request Token

Example Request

GET /api/pages
Host: sanaprotocolbuilder.me
Authorization: Token <token>

Example Response

[
  {
    "id":8,
    "display_index":0,
    "procedure":2,
    "elements":[

    ],
    "last_modified":"2016-03-06T23:47:29.543346Z",
    "created":"2016-03-06T23:47:29.543405Z",
    "show_if":[

    ]
  },
  {
    "id":9,
    "display_index":1,
    "procedure":2,
    "elements":[

    ],
    "last_modified":"2016-03-06T23:47:30.438138Z",
    "created":"2016-03-06T23:47:30.438169Z",
    "show_if":[

    ]
  },
  {
    "id":10,
    "display_index":2,
    "procedure":2,
    "elements":[

    ],
    "last_modified":"2016-03-06T23:47:31.023659Z",
    "created":"2016-03-06T23:47:31.023690Z",
    "show_if":[

    ]
  },
  {
    "id":11,
    "display_index":3,
    "procedure":2,
    "elements":[

    ],
    "last_modified":"2016-03-06T23:47:31.592751Z",
    "created":"2016-03-06T23:47:31.592780Z",
    "show_if":[

    ]
  },
  {
    "id":12,
    "display_index":4,
    "procedure":2,
    "elements":[

    ],
    "last_modified":"2016-03-06T23:47:32.153689Z",
    "created":"2016-03-06T23:47:32.153721Z",
    "show_if":[

    ]
  },
  {
    "id":13,
    "display_index":5,
    "procedure":2,
    "elements":[

    ],
    "last_modified":"2016-03-06T23:47:32.875413Z",
    "created":"2016-03-06T23:47:32.875441Z",
    "show_if":[

    ]
  }
]

Get one

To get a specific page that you own GET to /api/pages/{id}, Where id is the page's id.

Status Codes

200: Success

401: Invalid Request Token

404: Does not exist

Example Request

GET /api/pages/7
Host: sanaprotocolbuilder.me
Authorization: Token <token>

Example Response

{
  "id":7,
  "display_index":1,
  "procedure":8,
  "elements":[],
  "last_modified":"2016-03-06T23:33:32.595421Z",
  "created":"2016-03-06T23:33:32.595488Z",
  "show_if":[]
}