Data API Overview

Retrieving user data from Human API

πŸ“˜

For a full list of queries, see the API Reference.

What is the Data API?

The Data API is a REST API that provides comprehensive health data served via JSON for request and response payloads. Endpoints of the Data API can be found in the API Reference page.

🚧

This section assumes that you have registered users and have retrieved their access tokens using Connect. If you haven't done that yet, please go through the Web Guide section of the documentation.

Querying a User's Health Data

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:

curl -H "Authorization: Bearer demo" "https://api.humanapi.co/v1/human"

πŸ‘

Demo data

You can always give an endpoint a try with the access_token demo. See Demo Data for more info.

Before you start to write your data retrieval infrastructure you will want to review a few things:

  1. The Patterns and Conventions section, which covers all important conventions Human API follows.

  2. The Demo Data section, which covers how to work with demo data while you prototype and integrate.

  3. The API Reference page, which provides a comprehensive list of all the endpoints the Data API provides.

Setting Up Basic Data Retrieval

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:

var headers = {
  'Authorization': 'Bearer ' + accessToken,
  'Accept': 'application/json'
};
var url = 'https://api.humanapi.co/v1/human/test_results?limit=1'

request({
  method: 'GET',
  uri : url,
  headers : headers
  }, function (error, res, body) {
    var parsedResponse;
    if (error) {
      callback(new Error('Unable to connect to the Human API endpoint.'));
    } else {
      if(res.statusCode == 401) {
        logger.debug("Unauthorized request, validate access token");
        callback(null, { status: 'unauthorized' });
      } else {
        try {
          parsedResponse = JSON.parse(body);
        } catch (error) {
          return callback(new Error('Error parsing JSON response from Human API.'));
        }
        // At this point you can use the JSON object to access the results
        console.log("Latest test result name");
        console.log(parsedResponse[0]["name"]);
        return callback(null, parsedResponse);
      }
    }
});

That's all there is to it! Now that you have implemented 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