Fetch user placeline

ht-client can be used to fetch and poll for latest user placeline data (and other primitives). The library makes the api calls to HyperTrack backend, and continuously polls for the data to emit the latest value on regular interval.

Complete code for this tutorial is available here


1. Setting up client

ht-client and their dependencies need to be installed. Follow this tutorial to set that up.


var token = "sk_xxxxxxxxxxxxxxxxxxxx";
var client = htClient.initClient(token);


import {initClient} from "ht-client"

var token = "sk_xxxxxxxxxxxxxxxxxxxx";
var client = initClient(token);

2. Setting user_id for the placeline

usersClientFactory is a factory function which can be used initialized user client.

var usersClient = htClient.usersClientFactory();

usersClient contains all users related endpoints which can be used to fetch relevant data. For this tutorial we'll use placeline endpoint.

var userId = "<USER_ID>";

3. Subscribe to placeline data

placeline property of users client has a property data$ which is an observable<IUser>. Observables when subscribed to emits updated values after each poll.

var placelineData$ = usersClient.placeline.data$;

var placelineSub = placelineData$.subscribe((users) => {
  //users placeline data emitted at regular interval

4 Stop subscription (optional)

To stop polling and cleanup the subscription, set id as null and unsubscribe to the Subscriptions



1. Query parameters

The placeline data fetched by the api can be configured using different query parameters.

parameter example usage
date {date: "2017-11-06"} fetch placeline of any particular data. Date format should be YYYY-MM-DD
action_id {action_id: "ACTION_ID"} fetch placeline of any action
action_lookup_id {action_lookup_id: "ACTION_LOOKUP_ID"} fetch placeline of any action lookup id
action_collection_id {action_collection_id: "ACTION_COLLECTION_ID"} fetch placeline of any action collection id


let query = {date: "2017-11-06"};

2. Update Strategy

By default the client is configured to poll for updated data on regular interval. It can be configured to fetch the data only once. UsersClient has property updateStrategy which can take values of live and once. Default update strategy is set to live.



usersClient.placeline.updateStrategy = 'once'; //default is 'live'

3. Polling interval

By default the poll interval is set to 10 seconds/10000 msec. This can be configured by changing pollDuration property in UsersClient

usersClient.placeline.pollDuration = 5000; //5 secs, default to 10secs

results matching ""

    No results matching ""