{"_id":"5540026b23c53c0d00cccf19","user":"5539912a0074c80d00621b14","__v":30,"project":"551375e1d04af219007ddc52","category":{"_id":"5549346a6a82a10d00817a81","version":"551375e2d04af219007ddc55","__v":0,"pages":[],"project":"551375e1d04af219007ddc52","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-05T21:21:46.158Z","from_sync":false,"order":5,"slug":"managing-your-app","title":"Managing Your App"},"version":{"_id":"551375e2d04af219007ddc55","project":"551375e1d04af219007ddc52","__v":9,"createdAt":"2015-03-26T02:58:42.261Z","releaseDate":"2015-03-26T02:58:42.260Z","categories":["551375e2d04af219007ddc56","5514c6e9bc466623002afddb","5514c6f8fa9cbe2300847841","5514c6fd07274c0d00e620f4","553fe5fc23c53c0d00ccceb4","554113ad5cf9682100d61baa","5549346a6a82a10d00817a81","561be536a3df620d007a1851","563aef87ea247f0d0044d4de"],"is_deprecated":true,"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-04-28T21:58:03.891Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Batch Queries are one way to keep you user's information up-to-date. For best practices, see [Keeping User Data Up-to-date](doc:data-synchronization).\",\n  \"title\": \"Syncing User Data\"\n}\n[/block]\nTo make your data synchronization tasks more efficient you can take advantage of the batch query capabilities of the Application level API. This allows you to synchronize the data for all of the users of your app in one query per data type. You need to use the `updated_since` query parameter and keep track of the last query time so that you can retrieve only the data that has been updated since the last time you queried.\n\n#Endpoints\nBase URL\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"https://api.humanapi.co/v1\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nIndividual Endpoints\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"/apps/:clientId/users/activities\\n/apps/:clientId/users/activities/summaries\\n/apps/:clientId/users/heart_rates\\n/apps/:clientId/users/bmis\\n/apps/:clientId/users/body_fats\\n/apps/:clientId/users/heights\\n/apps/:clientId/users/weights\\n/apps/:clientId/users/blood_pressures\\n/apps/:clientId/users/blood_glucoses\\n/apps/:clientId/users/blood_oxygens\\n/apps/:clientId/users/sleeps\\n/apps/:clientId/users/sleeps/summaries\\n/apps/:clientId/users/genetic_traits\\n/apps/:clientId/users/locations\\n/apps/:clientId/users/food/meals\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\nThese endpoints replicate those available for the individual user queries. The payload data model is the same for individual and batch queries, except the batch query results return data for multiple users so you need to parse the data accordingly.\n\nAlthough [we recommend](http://hub.humanapi.co/v1.0/docs/data-synchronization) using [Notifications](doc:notifications) in tandem with batch queries, in some cases developers rely solely on batch queries for data synchronization. If you do so, it is recommended that you run the queries frequently to avoid accumulating a lot of data resulting in huge payloads and longer response times. A good role of thumb is to run your query as often as required to avoid having to paginate your queries. \n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"Do not perform regular batch queries without the `updated_since` query parameter. By supplying `updated_since` with your last query time, you can ensure that your queries are quick and efficient. \\n\\n* If `updated_since` is not specified, you will only get 24 hours of updated data. Additionally, the maximum amount of time that can be queried by batch will be 31 days.\\n\\n* To pull all of your application’s data, you will need to use a combination of `updated_since` and `updated_before` to pull data for time intervals no greater than 31 days per query.\",\n  \"title\": \"Updated_since is Required\"\n}\n[/block]\n#Example GET Query\n\nUsing curl command line:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl -X GET -H 'Accept: application/json' \\\\\\n    -u e7db255f4828e1d482743eba04faacb945ab7ca8: \\\\\\nhttps://api.humanapi.co/v1/apps/1d129c20acf6fcef9be0b067cc7859d872ed5ade/users/activities?updated_since=20130925T120000Z\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\n\nAn example payload looks like this.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[\\n  {\\n    id: \\\"52867cbfde3155565f000b01\\\",\\n    userId: \\\"51cc7cb31a154bf215000002\\\",\\n    humanId: \\\"7eddd553c81b8de9ac271bc21f50e32e\\\",\\n    startTime: \\\"2013-11-01T17:27:00.346Z\\\",\\n    endTime: \\\"2013-11-01T18:27:11.346Z\\\",\\n    type: \\\"walking\\\",\\n    source: \\\"runkeeper\\\",\\n    duration: 3611,\\n    distance: 1251,\\n    steps: 2689,\\n    calories: 482,\\n    timeZone: \\\"America/Los_Angeles\\\",\\n    sourceData: {},\\n    timeSeries: {},\\n    createdAt: \\\"2013-11-01T17:27:00.346Z\\\",\\n    updatedAt: \\\"2013-11-01T17:27:00.346Z\\\"\\n  },\\n  {\\n    id: \\\"52867cbfde3155565f000b02\\\",\\n    userId: \\\"538b9d3a9b1e35be7302607e\\\",\\n    humanId: \\\"5dc2527186aaf9de560e5841f1a44bd6\\\",\\n    startTime: \\\"2014-05-31T16:18:19.000Z\\\",\\n    endTime: \\\"2014-05-31T19:00:27.000Z\\\",\\n    type: \\\"cycling\\\",\\n    source: \\\"strava\\\",\\n    duration: 9728,\\n    distance: 45468.6,\\n    steps: 0,\\n    calories: 0,\\n    sourceData: {\\n      maxHeartrate: 196,\\n      averageHeartrate: 145,\\n      maxSpeed: 17.3,\\n      mapId: \\\"a147785724\\\",\\n      movingTime: 7782,\\n      type: \\\"Ride\\\"\\n    },\\n    createdAt: \\\"2014-05-31T19:03:32.032Z\\\",\\n    updatedAt: \\\"2014-05-31T19:03:32.032Z\\\"\\n  },\\n  {\\n    id: \\\"52867cbfde3155565f000b03\\\",\\n    userId: \\\"538029c700850beb2601c578\\\",\\n    humanId: \\\"7eddd553c81b8de9ac271bc21f50e32e\\\",\\n    startTime: \\\"2014-05-28T20:04:02.000Z\\\",\\n    endTime: \\\"2014-05-29T00:00:00.000Z\\\",\\n    type: \\\"walking\\\",\\n    source: \\\"mapmyfitness\\\",\\n    duration: 0,\\n    distance: 178636.74,\\n    steps: 0,\\n    calories: 1916,\\n    sourceData: { },\\n    createdAt: \\\"2014-05-31T00:21:09.386Z\\\",\\n    updatedAt: \\\"2014-05-31T00:21:09.386Z\\\"\\n  }\\n]\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Pagination\",\n  \"body\": \"The default number of results returned per query is 50 and the max is 500 by setting a higher `limit`. You can paginate through the rest of the results based on the documentation [here](http://hub.humanapi.co/docs/patterns-and-conventions-reference#pagination-conventions).\"\n}\n[/block]","excerpt":"","slug":"batch-queries","type":"basic","title":"Batch Queries"}
[block:callout] { "type": "info", "body": "Batch Queries are one way to keep you user's information up-to-date. For best practices, see [Keeping User Data Up-to-date](doc:data-synchronization).", "title": "Syncing User Data" } [/block] To make your data synchronization tasks more efficient you can take advantage of the batch query capabilities of the Application level API. This allows you to synchronize the data for all of the users of your app in one query per data type. You need to use the `updated_since` query parameter and keep track of the last query time so that you can retrieve only the data that has been updated since the last time you queried. #Endpoints Base URL [block:code] { "codes": [ { "code": "https://api.humanapi.co/v1", "language": "text" } ] } [/block] Individual Endpoints [block:code] { "codes": [ { "code": "/apps/:clientId/users/activities\n/apps/:clientId/users/activities/summaries\n/apps/:clientId/users/heart_rates\n/apps/:clientId/users/bmis\n/apps/:clientId/users/body_fats\n/apps/:clientId/users/heights\n/apps/:clientId/users/weights\n/apps/:clientId/users/blood_pressures\n/apps/:clientId/users/blood_glucoses\n/apps/:clientId/users/blood_oxygens\n/apps/:clientId/users/sleeps\n/apps/:clientId/users/sleeps/summaries\n/apps/:clientId/users/genetic_traits\n/apps/:clientId/users/locations\n/apps/:clientId/users/food/meals", "language": "text" } ] } [/block] These endpoints replicate those available for the individual user queries. The payload data model is the same for individual and batch queries, except the batch query results return data for multiple users so you need to parse the data accordingly. Although [we recommend](http://hub.humanapi.co/v1.0/docs/data-synchronization) using [Notifications](doc:notifications) in tandem with batch queries, in some cases developers rely solely on batch queries for data synchronization. If you do so, it is recommended that you run the queries frequently to avoid accumulating a lot of data resulting in huge payloads and longer response times. A good role of thumb is to run your query as often as required to avoid having to paginate your queries. [block:callout] { "type": "warning", "body": "Do not perform regular batch queries without the `updated_since` query parameter. By supplying `updated_since` with your last query time, you can ensure that your queries are quick and efficient. \n\n* If `updated_since` is not specified, you will only get 24 hours of updated data. Additionally, the maximum amount of time that can be queried by batch will be 31 days.\n\n* To pull all of your application’s data, you will need to use a combination of `updated_since` and `updated_before` to pull data for time intervals no greater than 31 days per query.", "title": "Updated_since is Required" } [/block] #Example GET Query Using curl command line: [block:code] { "codes": [ { "code": "curl -X GET -H 'Accept: application/json' \\\n -u e7db255f4828e1d482743eba04faacb945ab7ca8: \\\nhttps://api.humanapi.co/v1/apps/1d129c20acf6fcef9be0b067cc7859d872ed5ade/users/activities?updated_since=20130925T120000Z", "language": "curl" } ] } [/block] An example payload looks like this. [block:code] { "codes": [ { "code": "[\n {\n id: \"52867cbfde3155565f000b01\",\n userId: \"51cc7cb31a154bf215000002\",\n humanId: \"7eddd553c81b8de9ac271bc21f50e32e\",\n startTime: \"2013-11-01T17:27:00.346Z\",\n endTime: \"2013-11-01T18:27:11.346Z\",\n type: \"walking\",\n source: \"runkeeper\",\n duration: 3611,\n distance: 1251,\n steps: 2689,\n calories: 482,\n timeZone: \"America/Los_Angeles\",\n sourceData: {},\n timeSeries: {},\n createdAt: \"2013-11-01T17:27:00.346Z\",\n updatedAt: \"2013-11-01T17:27:00.346Z\"\n },\n {\n id: \"52867cbfde3155565f000b02\",\n userId: \"538b9d3a9b1e35be7302607e\",\n humanId: \"5dc2527186aaf9de560e5841f1a44bd6\",\n startTime: \"2014-05-31T16:18:19.000Z\",\n endTime: \"2014-05-31T19:00:27.000Z\",\n type: \"cycling\",\n source: \"strava\",\n duration: 9728,\n distance: 45468.6,\n steps: 0,\n calories: 0,\n sourceData: {\n maxHeartrate: 196,\n averageHeartrate: 145,\n maxSpeed: 17.3,\n mapId: \"a147785724\",\n movingTime: 7782,\n type: \"Ride\"\n },\n createdAt: \"2014-05-31T19:03:32.032Z\",\n updatedAt: \"2014-05-31T19:03:32.032Z\"\n },\n {\n id: \"52867cbfde3155565f000b03\",\n userId: \"538029c700850beb2601c578\",\n humanId: \"7eddd553c81b8de9ac271bc21f50e32e\",\n startTime: \"2014-05-28T20:04:02.000Z\",\n endTime: \"2014-05-29T00:00:00.000Z\",\n type: \"walking\",\n source: \"mapmyfitness\",\n duration: 0,\n distance: 178636.74,\n steps: 0,\n calories: 1916,\n sourceData: { },\n createdAt: \"2014-05-31T00:21:09.386Z\",\n updatedAt: \"2014-05-31T00:21:09.386Z\"\n }\n]", "language": "json" } ] } [/block] [block:callout] { "type": "info", "title": "Pagination", "body": "The default number of results returned per query is 50 and the max is 500 by setting a higher `limit`. You can paginate through the rest of the results based on the documentation [here](http://hub.humanapi.co/docs/patterns-and-conventions-reference#pagination-conventions)." } [/block]