POST child physical activity - ocariot/api-gateway GitHub Wiki
Description
Register a new physical activity and associate it to a Child.
Permissions:
-
Application users can record a physical activity for any child as long as the child exists.
-
A child can record a physical activity only for herself.
-
An Educator can record a physical activity for any Child who exists and belongs to one of their groups.
-
A Family user can record a physical activity for any Child who exists and is associated with it.
Scope
physicalactivities:create
URL
POST https://localhost/v1/children/{child_id}/physicalactivities
Parameters
child_id: string (A 24-byte hex ID)
Request body
{
"name": "Walk",
"start_time": "2019-12-14T12:52:59Z",
"end_time": "2019-12-14T13:12:37Z",
"duration": 1178000,
"calories": 109,
"steps": 1407,
"distance": 800,
"levels": [
{
"name": "sedentary",
"duration": 120000
},
{
"name": "lightly",
"duration": 60000
},
{
"name": "fairly",
"duration": 540000
},
{
"name": "very",
"duration": 420000
}
],
"heart_rate": {
"average": 107,
"out_of_range_zone": {
"min": 30,
"max": 91,
"duration": 0
},
"fat_burn_zone": {
"min": 91,
"max": 127,
"duration": 600000
},
"cardio_zone": {
"min": 127,
"max": 154,
"duration": 0
},
"peak_zone": {
"min": 154,
"max": 220,
"duration": 0
}
}
}
Curl example
curl -X POST "https://localhost/v1/children/5a62be07d6f33400146c9b61/physicalactivities" -H "accept: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type: application/json" -d "{"name":"Walk","start_time":"2018-12-14T12:52:59Z","end_time":"2018-12-14T13:12:37Z","duration":1178000,"calories":109,"steps":1407,"distance":800,"levels":[{"name":"sedentary","duration":120000},{"name":"lightly","duration":60000},{"name":"fairly","duration":540000},{"name":"very","duration":420000}],"heart_rate":{"average":107,"out_of_range_zone":{"min":30,"max":91,"duration":0},"fat_burn_zone":{"min":91,"max":127,"duration":600000},"cardio_zone":{"min":127,"max":154,"duration":0},"peak_zone":{"min":154,"max":220,"duration":0}}}"
Response body
-
201
Physical Activity saved sucessfully.{ "id": "5a62be07de34500146d9c544", "name": "Walk", "start_time": "2019-12-14T12:52:59Z", "end_time": "2019-12-14T13:12:37Z", "duration": 1178000, "calories": 109, "steps": 1407, "distance": 800, "levels": [ { "name": "sedentary", "duration": 120000 }, { "name": "lightly", "duration": 60000 }, { "name": "fairly", "duration": 540000 }, { "name": "very", "duration": 420000 } ], "heart_rate": { "average": 107, "out_of_range_zone": { "min": 30, "max": 91, "duration": 0 }, "fat_burn_zone": { "min": 91, "max": 127, "duration": 600000 }, "cardio_zone": { "min": 127, "max": 154, "duration": 0 }, "peak_zone": { "min": 154, "max": 220, "duration": 0 } }, "child_id": "5a62be07de34500146d9c544" }
-
207
Successful request, however, can have several status codes for the case of a list of submitted physical activities.{ "success": [ { "code": 201, "item": { "id": "5db6fa35fce8d130bf48a9d2", "start_time": "2019-12-03T12:52:59.000Z", "end_time": "2019-12-03T13:12:37.000Z", "duration": 1178000, "child_id": "5a62be07d6f33400146c9b61", "name": "Walk", "calories": 109, "steps": 1407, "distance": 800, "levels": [ { "name": "sedentary", "duration": 120000 }, { "name": "lightly", "duration": 60000 }, { "name": "fairly", "duration": 540000 }, { "name": "very", "duration": 420000 } ], "heart_rate": { "average": 107, "out_of_range_zone": { "min": 30, "max": 91, "duration": 0 }, "fat_burn_zone": { "min": 91, "max": 127, "duration": 600000 }, "cardio_zone": { "min": 127, "max": 154, "duration": 0 }, "peak_zone": { "min": 154, "max": 220, "duration": 0 } } } } ], "error": [ { "code": 409, "message": "Physical Activity is already registered...", "item": { "start_time": "2019-12-02T12:52:59.000Z", "end_time": "2019-12-02T13:12:37.000Z", "duration": 1178000, "child_id": "5a62be07d6f33400146c9b61", "name": "Walk", "calories": 109, "steps": 1407, "distance": 800, "levels": [ { "name": "sedentary", "duration": 120000 }, { "name": "lightly", "duration": 60000 }, { "name": "fairly", "duration": 540000 }, { "name": "very", "duration": 420000 } ], "heart_rate": { "average": 107, "out_of_range_zone": { "min": 30, "max": 91, "duration": 0 }, "fat_burn_zone": { "min": 91, "max": 127, "duration": 600000 }, "cardio_zone": { "min": 127, "max": 154, "duration": 0 }, "peak_zone": { "min": 154, "max": 220, "duration": 0 } } } } ] }
-
400
Validation errors-
- Example
{ "code": 400, "message": "Required fields were not provided...", "description": "start_time, end_time, duration, name, calories are required!" }
- Example
-
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!" }
- Pattern
-
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!" }
- Pattern
-
- Example
{ "code": 400, "message": "One or more request fields are invalid...", "description": "name must have at least one character!" }
- Example
-
- Example
{ "code": 400, "message": "One or more request fields are invalid...", "description": "name must be a string!" }
- Example
-
- Example
{ "code": 400, "message": "One or more request fields are invalid...", "description": "calories can't be negative!" }
- Naming pattern of attributes that have other objects as its type
levels.duration heart_rate.average heart_rate.out_of_range_zone.duration
- Example
-
- Example
{ "code": 400, "message": "One or more request fields are invalid...", "description": "duration must be a valid number!" }
- Example
-
Some invalid type in level
- Pattern
{ "code": 400, "message": "One or more request fields are invalid...", "description": "The names of the allowed levels are: sedentary, lightly, fairly, very." }
- Pattern
-
Invalid format of levels attribute
- Pattern
{ "code": 400, "message": "One or more request fields are invalid...", "description": "The levels array must have values for the following levels: sedentary, lightly, fairly, very." }
- Pattern
-
403
Permission Error -
409
Conflict Error