Language

Updating

Data can be updated by sending a PUT request to the /api/v2/data endpoint with the complete Data Record structure in the request body:

curl --request PUT \
  --url https://test.hubat.net/api/v2/data \
  --header 'content-type: application/json' \
  --header 'x-auth-token: ACCESS_TOKEN' \
  --data '[{"endpoint":"hat/locations","recordId":"e965e022-6613-476a-a0cd-1f587a41b148","data":{"id":85998,"data":{"locations":{"accuracy":"1000.0","latitude":"51.671358277138","longitude":"0.101014673709963","timestamp":"2017-04-23T16:11:17+0000"}},"name":"record 1","lastUpdated":"2017-04-23T16:11:17.000Z"}}]'
var data = JSON.stringify([
  {
    "endpoint": "hat/locations",
    "recordId": "e965e022-6613-476a-a0cd-1f587a41b148",
    "data": {
      "id": 85998,
      "data": {
        "locations": {
          "accuracy": "1000.0",
          "latitude": "51.671358277138",
          "longitude": "0.101014673709963",
          "timestamp": "2017-04-23T16:11:17+0000"
        }
      },
      "name": "record 1",
      "lastUpdated": "2017-04-23T16:11:17.000Z"
    }
  }
]);

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

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

xhr.open("PUT", "https://test.hubat.net/api/v2/data");
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",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => "[{\"endpoint\":\"hat/locations\",\"recordId\":\"e965e022-6613-476a-a0cd-1f587a41b148\",\"data\":{\"id\":85998,\"data\":{\"locations\":{\"accuracy\":\"1000.0\",\"latitude\":\"51.671358277138\",\"longitude\":\"0.101014673709963\",\"timestamp\":\"2017-04-23T16:11:17+0000\"}},\"name\":\"record 1\",\"lastUpdated\":\"2017-04-23T16:11:17.000Z\"}}]",
  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"

payload = "[{\"endpoint\":\"hat/locations\",\"recordId\":\"e965e022-6613-476a-a0cd-1f587a41b148\",\"data\":{\"id\":85998,\"data\":{\"locations\":{\"accuracy\":\"1000.0\",\"latitude\":\"51.671358277138\",\"longitude\":\"0.101014673709963\",\"timestamp\":\"2017-04-23T16:11:17+0000\"}},\"name\":\"record 1\",\"lastUpdated\":\"2017-04-23T16:11:17.000Z\"}}]"
headers = {
    'content-type': "application/json",
    'x-auth-token': "ACCESS_TOKEN"
    }

response = requests.request("PUT", url, data=payload, headers=headers)

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

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

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

request = Net::HTTP::Put.new(url)
request["content-type"] = 'application/json'
request["x-auth-token"] = 'ACCESS_TOKEN'
request.body = "[{\"endpoint\":\"hat/locations\",\"recordId\":\"e965e022-6613-476a-a0cd-1f587a41b148\",\"data\":{\"id\":85998,\"data\":{\"locations\":{\"accuracy\":\"1000.0\",\"latitude\":\"51.671358277138\",\"longitude\":\"0.101014673709963\",\"timestamp\":\"2017-04-23T16:11:17+0000\"}},\"name\":\"record 1\",\"lastUpdated\":\"2017-04-23T16:11:17.000Z\"}}]"

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

The above request is expected to effectively update only the accuracy field of the record already stored, however in practice the provided data replaces the whole record already stored in the HAT.

Deleting

Data is deleted by sending a DELETE request to the /api/v2/data endpoint with IDs of the records to be deleted in query parameters:

curl --request DELETE \
  --url 'https://test.hubat.net/api/v2/data?records=3474369e-2317-4ea2-9bc8-198700a1f9cb&records=6dcff611-45cb-49a9-82ca-318b9e5a3c17' \
  --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("DELETE", "https://test.hubat.net/api/v2/data?records=3474369e-2317-4ea2-9bc8-198700a1f9cb&records=6dcff611-45cb-49a9-82ca-318b9e5a3c17");
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?records=3474369e-2317-4ea2-9bc8-198700a1f9cb&records=6dcff611-45cb-49a9-82ca-318b9e5a3c17",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "DELETE",
  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"

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

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

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

url = URI("https://test.hubat.net/api/v2/data?records=3474369e-2317-4ea2-9bc8-198700a1f9cb&records=6dcff611-45cb-49a9-82ca-318b9e5a3c17")

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

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

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

If you are deleting multiple records in one go, just add a records parameter for each record ID. The response will contain an error if you are not authorized to delete any of the provided records or if any of the records do not exist - no records will be deleted in this case.