Skip to content

POST child sleep

JeffMedeiros edited this page Nov 29, 2019 · 1 revision

Description

Register a new sleep and associate it to a Child.

Permissions:

  • Application users can register a Sleep for any Child as long as it exists.

  • A Child can register a Sleep just for herself.

  • An Educator can register a Sleep for any Child who exists and belongs to one of their groups.

  • A Family user can register a Sleep for any Child who exists and is associated with it.

Scope

sleep:create

URL

POST https://localhost/v1/children/{child_id}/sleep

Parameters

child_id: string (A 24-byte hex ID)

Request body

{
  "start_time": "2019-08-18T01:40:30Z",
  "end_time": "2019-08-18T09:52:30Z",
  "duration": 29520000,
  "type": "classic",
  "pattern": {
    "data_set": [
      {
        "start_time": "2019-08-18T01:40:30.00Z",
        "name": "restless",
        "duration": 60000
      },
      {
        "start_time": "2019-08-18T01:41:30.00Z",
        "name": "asleep",
        "duration": 360000
      },
      {
        "start_time": "2019-08-18T01:47:30.00Z",
        "name": "restless",
        "duration": 240000
      },
      {
        "start_time": "2019-08-18T01:51:30.00Z",
        "name": "asleep",
        "duration": 60000
      },
      {
        "start_time": "2019-08-18T02:32:30.00Z",
        "name": "awake",
        "duration": 180000
      },
      {
        "start_time": "2019-08-18T06:47:30.00Z",
        "name": "restless",
        "duration": 60000
      },
      {
        "start_time": "2019-08-18T06:48:30.00Z",
        "name": "asleep",
        "duration": 2580000
      },
      {
        "start_time": "2019-08-18T07:31:30.00Z",
        "name": "restless",
        "duration": 120000
      },
      {
        "start_time": "2019-08-18T09:36:30.00Z",
        "name": "asleep",
        "duration": 960000
      }
    ]
  }
}

Curl example

curl -X POST "https://localhost/v1/children/5a62be07d6f33400146c9b61/sleep" -H "accept: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type: application/json" -d "{"start_time":"2018-08-18T01:40:30Z","end_time":"2018-08-18T09:52:30Z","duration":29520000,"type":"classic","pattern":{"data_set":[{"start_time":"2018-08-18T01:40:30.00Z","name":"restless","duration":60000},{"start_time":"2018-08-18T01:41:30.00Z","name":"asleep","duration":360000},{"start_time":"2018-08-18T01:47:30.00Z","name":"restless","duration":240000},{"start_time":"2018-08-18T01:51:30.00Z","name":"asleep","duration":60000},{"start_time":"2018-08-18T01:52:30.00Z","name":"restless","duration":60000},{"start_time":"2018-08-18T01:53:30.00Z","name":"asleep","duration":2100000},{"start_time":"2018-08-18T02:28:30.00Z","name":"restless","duration":240000},{"start_time":"2018-08-18T02:32:30.00Z","name":"awake","duration":180000},{"start_time":"2018-08-18T02:35:30.00Z","name":"asleep","duration":15120000},{"start_time":"2018-08-18T06:47:30.00Z","name":"restless","duration":60000},{"start_time":"2018-08-18T06:48:30.00Z","name":"asleep","duration":2580000},{"start_time":"2018-08-18T07:31:30.00Z","name":"restless","duration":120000},{"start_time":"2018-08-18T07:33:30.00Z","name":"asleep","duration":120000},{"start_time":"2018-08-18T07:35:30.00Z","name":"restless","duration":60000},{"start_time":"2018-08-18T07:36:30.00Z","name":"asleep","duration":1200000},{"start_time":"2018-08-18T07:56:30.00Z","name":"restless","duration":60000},{"start_time":"2018-08-18T07:57:30.00Z","name":"asleep","duration":2580000},{"start_time":"2018-08-18T08:40:30.00Z","name":"restless","duration":180000},{"start_time":"2018-08-18T08:43:30.00Z","name":"asleep","duration":1200000},{"start_time":"2018-08-18T09:03:30.00Z","name":"restless","duration":60000},{"start_time":"2018-08-18T09:04:30.00Z","name":"asleep","duration":1740000},{"start_time":"2018-08-18T09:03:30.00Z","name":"restless","duration":180000},{"start_time":"2018-08-18T09:36:30.00Z","name":"asleep","duration":960000}]}}"

Response body

  • 201 Sleep saved sucessfully.

    {
      "id": "3bc1274329fb282470e45004",
      "start_time": "2019-08-18T01:40:30Z",
      "end_time": "2019-08-18T09:52:30Z",
      "duration": 29520000,
      "type": "classic",
      "pattern": {
        "data_set": [
          {
            "start_time": "2019-08-18T01:40:30.00Z",
            "name": "restless",
            "duration": 60000
          },
          {
            "start_time": "2019-08-18T01:41:30.00Z",
            "name": "asleep",
            "duration": 360000
          },
          {
            "start_time": "2019-08-18T01:47:30.00Z",
            "name": "restless",
            "duration": 240000
          },
          {
            "start_time": "2019-08-18T01:51:30.00Z",
            "name": "asleep",
            "duration": 60000
          },
          {
            "start_time": "2019-08-18T02:32:30.00Z",
            "name": "awake",
            "duration": 180000
          },
          {
            "start_time": "2019-08-18T06:47:30.00Z",
            "name": "restless",
            "duration": 60000
          },
          {
            "start_time": "2019-08-18T06:48:30.00Z",
            "name": "asleep",
            "duration": 2580000
          },
          {
            "start_time": "2019-08-18T07:31:30.00Z",
            "name": "restless",
            "duration": 120000
          },
          {
            "start_time": "2019-08-18T09:36:30.00Z",
            "name": "asleep",
            "duration": 960000
          }
        ],
        "summary": {
          "asleep": {
            "count": 4,
            "duration": 3960000
          },
          "awake": {
            "count": 1,
            "duration": 180000
          },
          "restless": {
            "count": 4,
            "duration": 480000
          }
        }
      },
      "child_id": "5a62be07de34500146d9c544"
    }        
  • 207 Successful request, however, can have several status codes for the case of a list of submitted sleep records.

    {
      "success": [
        {
          "code": 201,
          "item": {
            "id": "5db6fa35fce8d130bf48a9d2",
            "start_time": "2019-08-18T01:40:30Z",
            "end_time": "2019-08-18T09:52:30Z",
            "duration": 29520000,
            "type": "classic",
            "pattern": {
                "data_set": [
                  {
                    "start_time": "2019-08-18T01:40:30.00Z",
                    "name": "restless",
                    "duration": 60000
                  },
                  {
                    "start_time": "2019-08-18T01:41:30.00Z",
                    "name": "asleep",
                    "duration": 360000
                  },
                  {
                    "start_time": "2019-08-18T01:47:30.00Z",
                    "name": "restless",
                    "duration": 240000
                  },
                  {
                    "start_time": "2019-08-18T01:51:30.00Z",
                    "name": "asleep",
                    "duration": 60000
                  },
                  {
                    "start_time": "2019-08-18T02:32:30.00Z",
                    "name": "awake",
                    "duration": 180000
                  },
                  {
                    "start_time": "2019-08-18T06:47:30.00Z",
                    "name": "restless",
                    "duration": 60000
                  },
                  {
                    "start_time": "2019-08-18T06:48:30.00Z",
                    "name": "asleep",
                    "duration": 2580000
                  },
                  {
                    "start_time": "2019-08-18T07:31:30.00Z",
                    "name": "restless",
                    "duration": 120000
                  },
                  {
                    "start_time": "2019-08-18T09:36:30.00Z",
                    "name": "asleep",
                    "duration": 960000
                  }
                ],
                "summary": {
                  "asleep": {
                    "count": 4,
                    "duration": 3960000
                  },
                  "awake": {
                    "count": 1,
                    "duration": 180000
                  },
                  "restless": {
                    "count": 4,
                    "duration": 480000
                  }
                }
            },
            "child_id": "5a62be07de34500146d9c544"
          }
        }
      ],
      "error": [
        {
          "code": 409,
          "message": "Sleep is already registered...",
          "item": {
            "start_time": "2019-08-21T01:40:30Z",
            "end_time": "2019-08-21T09:52:30Z",
            "duration": 29520000,
            "type": "classic",
            "pattern": {
                "data_set": [
                  {
                    "start_time": "2019-08-18T01:40:30.00Z",
                    "name": "restless",
                    "duration": 60000
                  },
                  {
                    "start_time": "2019-08-18T01:41:30.00Z",
                    "name": "asleep",
                    "duration": 360000
                  },
                  {
                    "start_time": "2019-08-18T01:47:30.00Z",
                    "name": "restless",
                    "duration": 240000
                  },
                  {
                    "start_time": "2019-08-18T01:51:30.00Z",
                    "name": "asleep",
                    "duration": 60000
                  },
                  {
                    "start_time": "2019-08-18T02:32:30.00Z",
                    "name": "awake",
                    "duration": 180000
                  },
                  {
                    "start_time": "2019-08-18T06:47:30.00Z",
                    "name": "restless",
                    "duration": 60000
                  },
                  {
                    "start_time": "2019-08-18T06:48:30.00Z",
                    "name": "asleep",
                    "duration": 2580000
                  },
                  {
                    "start_time": "2019-08-18T07:31:30.00Z",
                    "name": "restless",
                    "duration": 120000
                  },
                  {
                    "start_time": "2019-08-18T09:36:30.00Z",
                    "name": "asleep",
                    "duration": 960000
                  }
                ],
                "summary": {
                  "asleep": {
                    "count": 4,
                    "duration": 3960000
                  },
                  "awake": {
                    "count": 1,
                    "duration": 180000
                  },
                  "restless": {
                    "count": 4,
                    "duration": 480000
                  }
                }
            },
            "child_id": "5a62be07de34500146d9c544"
          }
        }
      ]
    }
  • 400 Validation errors

    • Invalid JSON format

    • Invalid child id

    • Child does not exist

    • Missing fields

      • Example
        {
          "code": 400,
          "message": "Required fields were not provided...",
          "description": "start_time, end_time, duration, type, pattern are required!"
        }
    • Missing data_set

      • Example
        {
          "code": 400,
          "message": "Required fields were not provided...",
          "description": "pattern.data_set is required!"
        }
    • Empty data_set

      • Example
        {
          "code": 400,
          "message": "One or more request fields are invalid...",
          "description": "pattern.data_set must not be empty!"
        }
    • Invalid date

    • end_time older than start_time

      • Pattern
        {
          "code": 400,
          "message": "One or more request fields are invalid...",
          "description": "The end_time parameter can not contain an older date than that the start_time parameter!"
        }
    • Invalid duration parameter

      • Pattern
        {
          "code": 400,
          "message": "One or more request fields are invalid...",
          "description": "duration value does not match values passed in start_time and end_time parameters!"
        }
    • Negative number

      • Example
        {
          "code": 400,
          "message": "One or more request fields are invalid...",
          "description": "duration can't be negative!"
        }
    • Invalid number

      • Example
        {
          "code": 400,
          "message": "One or more request fields are invalid...",
          "description": "duration must be a valid number!"
        }
      • Naming pattern of attributes that have other objects as its type
        pattern.data_set.duration
    • Invalid sleep type

      • Pattern
        {
          "code": 400,
          "message": "One or more request fields are invalid...",
          "description": "The names of the allowed Sleep Pattern types are: classic, stages."
        }
    • Some invalid type in data_set items

      • Pattern
        {
          "code": 400,
          "message": "One or more request fields are invalid...",
          "description": "The names of the allowed data_set patterns are: asleep, restless, awake." || "The names of the allowed data_set patterns are: deep, light, rem, awake."
        }
  • 401 Unauthorized Error

  • 403 Permission Error

  • 409 Conflict Error

  • 429 Too Many Requests Error

  • 500 Internal Server Error

OCARIoT users

Integration endpoints

auth

users

institutions

children

children.physicalactivities

children.logs

children.sleep

children.weights

children.bodyfats

educators

educators.children.groups

families

families.children

healthprofessionals

healthprofessionals.children.groups

applications

institutions.environments

fitbit

fitbit.subscriber

users.fitbit.auth

users.fitbit.sync

Error patterns

400 Validation Errors

Clone this wiki locally