Language

The most important step for an application developer is to access data. Once a Data Debit has been both proposed and approved by the HAT owner, it is achieved with a simple GET /api/v2/data-debit/DATA_DEBIT_ID/values call.

Using the previous example:

curl --request GET \
  --url https://test.hubat.net/api/v2/data-debit/userprofile/values \
  --header 'content-type: application/json' \
  --header 'x-auth-token: ACCESS_TOKEN'
var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://test.hubat.net/api/v2/data-debit/userprofile/values");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("x-auth-token", "ACCESS_TOKEN");

xhr.send(data);
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://test.hubat.net/api/v2/data-debit/userprofile/values",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "content-type: application/json",
    "x-auth-token: ACCESS_TOKEN"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import requests

url = "https://test.hubat.net/api/v2/data-debit/userprofile/values"

headers = {
    'content-type': "application/json",
    'x-auth-token': "ACCESS_TOKEN"
    }

response = requests.request("GET", url, headers=headers)

print(response.text)
require 'uri'
require 'net/http'

url = URI("https://test.hubat.net/api/v2/data-debit/userprofile/values")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(url)
request["content-type"] = 'application/json'
request["x-auth-token"] = 'ACCESS_TOKEN'

response = http.request(request)
puts response.read_body

If the data debit is enabled, the response is exactly the same as if you were using Data Bundles directly:


HTTP/1.1 200 OK
Content-Type: application/json


{
  "profile": [
    {
      "endpoint": "rumpel/profile",
      "recordId": "9b136020-372a-4777-81f9-2c4ce6925aea",
      "data": {
        "profile": {
          "website": {
            "link": "https://example.com",
            "private": "false"
          },
          "nick": {
            "private": "true",
            "name": ""
          },
          "primary_email": {
            "value": "testuser@example.com",
            "private": "false"
          },
          "private": "false",
          "youtube": {
            "link": "",
            "private": "true"
          },
          "address_global": {
            "city": "London",
            "county": "",
            "country": "UK",
            "private": "true"
          },
          "age": {
            "group": "",
            "private": "true"
          },
          "personal": {
            "first_name": "",
            "private": "false",
            "preferred_name": "Test",
            "last_name": "User",
            "middle_name": "",
            "title": ""
          },
          "blog": {
            "link": "",
            "private": "false"
          },
          "facebook": {
            "link": "",
            "private": "false"
          },
          "address_details": {
            "no": "",
            "street": "",
            "private": "false",
            "postcode": ""
          },
          "emergency_contact": {
            "first_name": "",
            "private": "true",
            "relationship": "",
            "last_name": "",
            "mobile": ""
          },
          "alternative_email": {
            "private": "true",
            "value": ""
          },
          "fb_profile_photo": {
            "private": "false"
          },
          "twitter": {
            "link": "",
            "private": "false"
          },
          "about": {
            "body": "A short bio about me shown on my PHATA",
            "private": "false",
            "title": "Me the Test User"
          },
          "mobile": {
            "no": "",
            "private": "true"
          },
          "gender": {
            "type": "",
            "private": "true"
          }
        }
      }
    }
  ],
  "location": [
    {
      "endpoint": "rumpel/locations",
      "recordId": "e965e022-6613-476a-a0cd-1f587a41b148",
      "data": {
        "latitude": "51.671358277138",
        "longitude": "0.101014673709963"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "8f7afa92-39e2-48ab-8028-f5aebaa9918e",
      "data": {
        "latitude": "51.6658257133844",
        "longitude": "0.080477950927866"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "fcf1a26b-e49f-4457-915b-156e14140f38",
      "data": {
        "latitude": "51.674001392439",
        "longitude": "0.100905202634514"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "6a858d87-899e-4961-b722-0738d07c755e",
      "data": {
        "latitude": "51.6712232446779",
        "longitude": "0.0961801595986785"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "d3a6f04b-4df6-4888-a7b0-c1d5ca272de9",
      "data": {
        "latitude": "51.6641215101037",
        "longitude": "0.0641066288762133"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "f5ecf3b2-acb8-415b-bbc0-c461ae4b6d02",
      "data": {
        "latitude": "51.6638846789036",
        "longitude": "0.0876670796424967"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "0a34f819-04fa-4ca3-b487-83dbfd88bc5e",
      "data": {
        "latitude": "51.6638664482643",
        "longitude": "0.0804444774986063"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "25fbf064-a84f-47be-aa6d-58e5e8834648",
      "data": {
        "latitude": "51.6654130770375",
        "longitude": "0.0760907493532413"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "6875b1e8-3210-4b18-abaa-a50d4af688a4",
      "data": {
        "latitude": "51.650111765824",
        "longitude": "0.0816392546856438"
      }
    },
    {
      "endpoint": "rumpel/locations",
      "recordId": "082f2805-013c-490f-be5f-d9cdccea0231",
      "data": {
        "latitude": "51.6679758858417",
        "longitude": "0.073134033009478"
      }
    }
  ]
}

If, on the other hand, you try to request data from a Data Debit that has not been enabled, you will receive an error:


HTTP/1.1 400 Bad Request
Content-Type: application/json


{
  "message": "Bad Request",
  "cause": "Data Debit locationlocationlocation not enabled"
}

That’s it! You have now successfully received data from a HAT user using a Data Debit agreement.