{"_id":"564d1afc4567342100ad96c6","__v":6,"version":{"_id":"564d1af84567342100ad96aa","project":"551375e1d04af219007ddc52","__v":1,"createdAt":"2015-11-19T00:42:32.705Z","releaseDate":"2015-11-19T00:42:32.705Z","categories":["564d1af94567342100ad96ab","564d1af94567342100ad96ac","564d1af94567342100ad96ad","564d1af94567342100ad96ae","564d1af94567342100ad96af","564d1af94567342100ad96b0","564d1af94567342100ad96b1","564d1af94567342100ad96b2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.1.0","version":"1.1"},"project":"551375e1d04af219007ddc52","category":{"_id":"564d1af94567342100ad96b0","__v":1,"pages":["564d1afc4567342100ad96c4","564d1afc4567342100ad96c5","564d1afc4567342100ad96c6"],"project":"551375e1d04af219007ddc52","version":"564d1af84567342100ad96aa","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"},"user":"5539912a0074c80d00621b14","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]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Only available for Wellness\",\n  \"body\": \"Batch Queries are currently not available for the Medical API\"\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](doc:application-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#Authentication\nAuthentication for Batch Queries is the same as that for the [Application API](doc:application-api). Instead of user accessTokens, which authorize access to an individual user's data, you will need to use your `App Key` to authorize the request on behalf of your full application. The `App Key` should be sent sent as the username of your request with the password left blank. See the example below for what this looks like:\n\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]\nAn example activity payload is shown below. It is the same format as the standard endpoint except each record can have a different `humanId`:\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: \\\"55d894b33a942540ac4b93dfd493eef1\\\",\\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: \\\"3b9e7162aea8280b3661f25784b3e9ba\\\",\\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] [block:callout] { "type": "info", "title": "Only available for Wellness", "body": "Batch Queries are currently not available for the Medical API" } [/block] To make your data synchronization tasks more efficient you can take advantage of the batch query capabilities of the [Application level API](doc:application-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] #Authentication Authentication for Batch Queries is the same as that for the [Application API](doc:application-api). Instead of user accessTokens, which authorize access to an individual user's data, you will need to use your `App Key` to authorize the request on behalf of your full application. The `App Key` should be sent sent as the username of your request with the password left blank. See the example below for what this looks like: #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 activity payload is shown below. It is the same format as the standard endpoint except each record can have a different `humanId`: [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: \"55d894b33a942540ac4b93dfd493eef1\",\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: \"3b9e7162aea8280b3661f25784b3e9ba\",\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]