Skip to content

POST child sleep

Jefferson Medeiros edited this page Feb 7, 2020 · 6 revisions

Description

Register a new sleep and associate it to a Child.

URL

POST https://localhost:4001/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:4001/v1/children/5a62be07d6f33400146c9b61/sleep" -H "accept: application/json" -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

    • 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 datetime

    • Invalid date

      • Pattern
        {
          "code": 400,
          "message": "Datetime: {datetime}, is not in valid ISO 8601 format."
        }
    • 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!"
        }
    • Invalid number

      • Example
        {
          "code": 400,
          "message": "One or more request fields are invalid...",
          "description": "duration must be an integer equal to or greater than zero."
        }
      • 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."
        }
  • 409 Conflict Error

  • 500 Internal Server Error

Clone this wiki locally