{"__v":6,"_id":"564d1afb4567342100ad96bb","category":{"__v":1,"_id":"564d1af94567342100ad96ae","pages":["564d1afb4567342100ad96bb","564d1afb4567342100ad96bc","564d1afb4567342100ad96bd","564d1afb4567342100ad96be","564d1afb4567342100ad96bf"],"project":"551375e1d04af219007ddc52","version":"564d1af84567342100ad96aa","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-27T02:56:56.435Z","from_sync":false,"order":3,"slug":"data-retrieval","title":"Data Retrieval"},"project":"551375e1d04af219007ddc52","user":"5539912a0074c80d00621b14","version":{"__v":1,"_id":"564d1af84567342100ad96aa","project":"551375e1d04af219007ddc52","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"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-04-29T17:50:35.736Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"For a full list of queries, see the [API Reference](doc:api-reference-1).\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"What is the Data API?\"\n}\n[/block]\n\nThe Data API is a REST API that provides comprehensive health data served via JSON for request and response payloads. \n\nThe Data API is composed of [two distinct types](doc:data-types) of health data:\n\n- **Wellness** - personal health data from wearable devices and apps\n- **Medical** - patient medial records from health providers\n\nThe information in this guide and others is primarily focused on the Wellness API, but endpoints for both sections of the API can be found on the [API Reference](doc:api-reference-1) page. If you are interested in learning more about the Medical API, please [let us know.](mailto:enterprise:::at:::humanapi.co) \n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"This section assumes that you have registered users and have retrieved their access tokens using the Human Connect popup. If you haven't done that yet, please go through the [Authenticating Users](doc:overview-of-human-connect) section of the documentation.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Querying a User's Health Data\"\n}\n[/block]\nTo query a user's health data all you need to do is use their `accessToken` in a GET request to one of the Human API endpoints. A standard query looks like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl https://api.humanapi.co/v1/human?access_token=<access_token>\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Demo Data\",\n  \"body\": \"You can always give an endpoint a try with the access_token `demo`. See [Demo Data](doc:demo-data) for more info.\"\n}\n[/block]\n\nBefore you start to write your data retrieval infrastructure you will want to review a few things:\n\n\n1. The [Patterns and Conventions](doc:patterns-and-conventions-reference) section, which covers all important conventions Human API follows.\n\n2. The [SDKs and Libraries](doc:sdks-and-libraries) section, which has examples and libraries in various languages you can use.\n\n3. The [Demo Data](doc:demo-data) section, which covers how to work with demo data while you prototype and integrate.\n\n4. The [API Reference](doc:api-reference-1) page, which provides a comprehensive list of all the endpoints the Data API provides.\n\n\n\n#Setting Up Your Data Retrieval Infrastructure\nNow that you know how to query an individual user's health data, you need to set up your data retrieval infrastructure. An example of a basic data retrieval using Node.js would be:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var headers = {\\n  'Authorization': 'Bearer ' + accessToken,\\n  'Accept': 'application/json'\\n};\\nvar url = 'https://api.humanapi.co/v1/human'\\n\\nrequest({\\n  method: 'GET',\\n  uri : url,\\n  headers : headers\\n  }, function (error, res, body) {\\n    var parsedResponse;\\n    if (error) {\\n      callback(new Error('Unable to connect to the Human API endpoint.'));\\n    } else {\\n      if(res.statusCode == 401) {\\n        logger.debug(\\\"Unauthorized request, validate access token\\\");\\n        callback(null, { status: 'unauthorized' });\\n      } else {\\n        try {\\n          parsedResponse = JSON.parse(body);\\n        } catch (error) {\\n          return callback(new Error('Error parsing JSON response from Human API.'));\\n        }\\n        // At this point you can use the JSON object to access the results\\n        console.log(\\\"Latest blood glucose measurement\\\");\\n        console.log(parsedResponse.bloodGlucose.value);\\n        return callback(null, parsedResponse);\\n      }\\n    }\\n});\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\nThat's all there is to it! Now that you have implemented Human Connect and started to retrieve data via the Data API, you can continue building out your application. \n\nSince you have the basics down, you may be interested in learning more about:\n\n# Best Practices\n\n* [Data Synchronization](doc:data-synchronization) - Keeping user data in sync with your database\n* [Data Availability & Design](doc:data-availability) - Setting expectations for your users\n\n#Displaying Data\nCheck out the **Chart API** for a quick and easy way to display data in your application.\n* [Chart API Overview](doc:chart-api) \n* [Customizing Charts](doc:custom-charts) \n\nFinally, if you run into any other issues, drop us a line at support@humanapi.co and we'd be happy to help.","excerpt":"Retrieving user data from Human API","slug":"data-overview","type":"basic","title":"Data API Overview"}

Data API Overview

Retrieving user data from Human API

[block:callout] { "type": "info", "body": "For a full list of queries, see the [API Reference](doc:api-reference-1)." } [/block] [block:api-header] { "type": "basic", "title": "What is the Data API?" } [/block] The Data API is a REST API that provides comprehensive health data served via JSON for request and response payloads. The Data API is composed of [two distinct types](doc:data-types) of health data: - **Wellness** - personal health data from wearable devices and apps - **Medical** - patient medial records from health providers The information in this guide and others is primarily focused on the Wellness API, but endpoints for both sections of the API can be found on the [API Reference](doc:api-reference-1) page. If you are interested in learning more about the Medical API, please [let us know.](mailto:enterprise@humanapi.co) [block:callout] { "type": "warning", "body": "This section assumes that you have registered users and have retrieved their access tokens using the Human Connect popup. If you haven't done that yet, please go through the [Authenticating Users](doc:overview-of-human-connect) section of the documentation." } [/block] [block:api-header] { "type": "basic", "title": "Querying a User's Health Data" } [/block] To query a user's health data all you need to do is use their `accessToken` in a GET request to one of the Human API endpoints. A standard query looks like this: [block:code] { "codes": [ { "code": "curl https://api.humanapi.co/v1/human?access_token=<access_token>", "language": "curl" } ] } [/block] [block:callout] { "type": "success", "title": "Demo Data", "body": "You can always give an endpoint a try with the access_token `demo`. See [Demo Data](doc:demo-data) for more info." } [/block] Before you start to write your data retrieval infrastructure you will want to review a few things: 1. The [Patterns and Conventions](doc:patterns-and-conventions-reference) section, which covers all important conventions Human API follows. 2. The [SDKs and Libraries](doc:sdks-and-libraries) section, which has examples and libraries in various languages you can use. 3. The [Demo Data](doc:demo-data) section, which covers how to work with demo data while you prototype and integrate. 4. The [API Reference](doc:api-reference-1) page, which provides a comprehensive list of all the endpoints the Data API provides. #Setting Up Your Data Retrieval Infrastructure Now that you know how to query an individual user's health data, you need to set up your data retrieval infrastructure. An example of a basic data retrieval using Node.js would be: [block:code] { "codes": [ { "code": "var headers = {\n 'Authorization': 'Bearer ' + accessToken,\n 'Accept': 'application/json'\n};\nvar url = 'https://api.humanapi.co/v1/human'\n\nrequest({\n method: 'GET',\n uri : url,\n headers : headers\n }, function (error, res, body) {\n var parsedResponse;\n if (error) {\n callback(new Error('Unable to connect to the Human API endpoint.'));\n } else {\n if(res.statusCode == 401) {\n logger.debug(\"Unauthorized request, validate access token\");\n callback(null, { status: 'unauthorized' });\n } else {\n try {\n parsedResponse = JSON.parse(body);\n } catch (error) {\n return callback(new Error('Error parsing JSON response from Human API.'));\n }\n // At this point you can use the JSON object to access the results\n console.log(\"Latest blood glucose measurement\");\n console.log(parsedResponse.bloodGlucose.value);\n return callback(null, parsedResponse);\n }\n }\n});\n", "language": "javascript" } ] } [/block] That's all there is to it! Now that you have implemented Human Connect and started to retrieve data via the Data API, you can continue building out your application. Since you have the basics down, you may be interested in learning more about: # Best Practices * [Data Synchronization](doc:data-synchronization) - Keeping user data in sync with your database * [Data Availability & Design](doc:data-availability) - Setting expectations for your users #Displaying Data Check out the **Chart API** for a quick and easy way to display data in your application. * [Chart API Overview](doc:chart-api) * [Customizing Charts](doc:custom-charts) Finally, if you run into any other issues, drop us a line at support@humanapi.co and we'd be happy to help.