GET Check-in Activities – Client examples

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * CheckInActivity client demonstrates fetching checkIn activities for a given zone using the 'request' node module.
 * 100 Check-in activities are returned per call, increment the page number parameter to get records corresponding to the page
 * This API service also accepts a date range as parameter(optional) where records within the start date and the end date range are returned
 */
var request             = require('request');
var bdCustomerApiKey    = "b2a9e860-2890-11e6-8148-0639e7649356"; //This key is generated by Bluedot Point Access UI when your account is created.
var bdApplicationApiKey = "14163ef0-2891-11e6-8148-0639e7649356"; //This apiKey is generated when you create an application.
var bdZoneId            = "c6814aba-d582-4b9e-8788-924f1a0a4c8a"; //This is the ID of the zone for which the check-in data is needed.
var receivedAtStart     = "2016-06-12";
var receivedAtEnd       = "2016-06-18";
//Increment the page number to get the next 100
//Example with Date
request.get ( 'https://api.bluedotinnovation.com/2/checkinactivities?customerApiKey=' + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey +
                "&zoneId=" + bdZoneId  + "&receivedAtStart="+ receivedAtStart + "&receivedAtEnd=" + receivedAtEnd + "&pageNumber=0",
    function (error, response)
    {
        if (error) {
            console.log(error);
        }
        var result = response.body;
        if( typeof result !== 'string' ) {
            console.log("Error in response");
            return;
            result = JSON.stringify(result)
        }
        console.log(result);
    }
);
package com.bluedotinnovation.checkin;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.bluedotinnovation.common.BDCommon;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * CheckInActivity client demonstrates fetching checkIn activities for a given zone.
 * 100 CheckIn activities are returned per call, increment the page number parameter to get records corresponding to the page
 * This api also accepts a date range as parameter(optional) where records within the start date and the end date range are returned
 */
public class BDCheckinActivityClient extends BDCommon {
     
    private static String bdCustomerApiKey    = "b2a9e860-2890-11e6-8148-0639e7649356"; //This key is generated by Bluedot Point Access UI when your account is created.
    private static String bdApplicationApiKey = "14163ef0-2891-11e6-8148-0639e7649356"; //This apiKey is generated when you create an application
    private static String bdZoneId            = "c6814aba-d582-4b9e-8788-924f1a0a4c8a"; //This is the id of the zone being updated. This can be fetched by calling This can be fetched by calling GET Zones API API
    private static String receivedAtStart     = "2016-06-05";
    private static String receivedAtEnd       = "2016-06-07";
    private static String checkInTimeStart    = "2016-09-13";
    private static String checkInTimeEnd      = "2016-09-05";   
    private static String bdRestBaseUrl       = "https://api.bluedotinnovation.com/2/checkinactivities";
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        //getAllCheckInActivitesByApplication();
        getAllCheckInActivitesByZone();
        //getCheckInActivitiesByReceivedAtDateRange();
        //getCheckInActivitiesByCheckInTimeDateRange
         
    }
     
    public static void getAllCheckInActivitesByApplication() throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdRestUrl = bdRestBaseUrl + "?&customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey + "&pageNumber=0";
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
        HttpGet request            = new HttpGet(bdRestUrl);
        HttpResponse httpResponse  = httpRestClient.execute(request);
         
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            BufferedReader rd          = new BufferedReader (new InputStreamReader
                                        (httpResponse.getEntity().getContent()));
            JSONParser parser          = new JSONParser();
            String bdChecInRecords;
             
            while ((bdChecInRecords = rd.readLine()) != null) {
                 Object object                = parser.parse(bdChecInRecords);
                 JSONArray bdCheckInJsonArry  = (JSONArray) object;
                 for (Object checkInObject : bdCheckInJsonArry) {
                     JSONObject jsonObject = (JSONObject) checkInObject;
                      
                     /*Print checkIn records returned*/             
                     System.out.println("Check-in ID : " + jsonObject.get("checkInId").toString());
                     System.out.println("Check-in Time : " +  jsonObject.get("CheckInTime"));
                     System.out.println("Zone ID :  " + jsonObject.get("zoneId"));
                     System.out.println("Zone Name :  " + jsonObject.get("zoneName"));
                     System.out.println("Device Speed : " + jsonObject.get("deviceSpeed"));
                     System.out.println("Device Type : " + jsonObject.get("deviceType"));
                     System.out.println("Installation Ref : " + jsonObject.get("installRef")); // This is a fully randomised id and the real application id or device id is never stored in the db
                     System.out.println("---------\n");
                }          
            }
        } else {
            InputStream inputStream = httpResponse.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }
    }
    public static void getAllCheckInActivitesByZone() throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdRestUrl = bdRestBaseUrl + "?&customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey + "&zoneId=" + bdZoneId + "&pageNumber=0";
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
        HttpGet request            = new HttpGet(bdRestUrl);
        HttpResponse httpResponse  = httpRestClient.execute(request);
         
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            BufferedReader rd          = new BufferedReader (new InputStreamReader
                                        (httpResponse.getEntity().getContent()));
            JSONParser parser          = new JSONParser();
            String bdChecInRecords;
             
            while ((bdChecInRecords = rd.readLine()) != null) {
                 Object object                = parser.parse(bdChecInRecords);
                 JSONArray bdCheckInJsonArry  = (JSONArray) object;
                 for (Object checkInObject : bdCheckInJsonArry) {
                     JSONObject jsonObject = (JSONObject) checkInObject;
                      
                     /*Print checkIn records returned*/             
                     System.out.println("Check-in ID : " + jsonObject.get("checkInId").toString());
                     System.out.println("Check-in Time : " +  jsonObject.get("CheckInTime"));
                     System.out.println("Zone ID :  " + jsonObject.get("zoneId"));
                     System.out.println("Zone Name :  " + jsonObject.get("zoneName"));
                     System.out.println("Device Speed : " + jsonObject.get("deviceSpeed"));
                     System.out.println("Device Type : " + jsonObject.get("deviceType"));
                     System.out.println("Installation Ref : " + jsonObject.get("installRef")); // This is a fully randomised id and the real application id or device id is never stored in the db
                     System.out.println("---------\n");
                }          
            }
        } else {
            InputStream inputStream = httpResponse.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }
    }
     
    public static void getCheckInActivitiesByReceivedAtDateRange() throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdRestUrl = bdRestBaseUrl + "?&customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey +
                "&receivedAtStart=" + receivedAtStart + "&receivedAtEnd=" + receivedAtEnd + "&pageNumber=0";
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
        HttpGet request            = new HttpGet(bdRestUrl);
        HttpResponse httpResponse  = httpRestClient.execute(request);
         
        if (httpResponse.getStatusLine().getStatusCode() == 200){
            BufferedReader rd          = new BufferedReader (new InputStreamReader
                                        (httpResponse.getEntity().getContent()));
            JSONParser parser          = new JSONParser();
            String bdChecInRecords;
             
            while ( (bdChecInRecords = rd.readLine() ) != null) {
                 Object object                = parser.parse(bdChecInRecords);
                 JSONArray bdCheckInJsonArry  = (JSONArray) object;
                  
                 for (Object checkInObject : bdCheckInJsonArry) {
                      
                     JSONObject jsonObject        = (JSONObject) checkInObject;
                      
                     /*Print checkIn records returned*/             
                     System.out.println("Check-in ID : " + jsonObject.get("checkInId").toString());
                     System.out.println("Check-in Time : " +  jsonObject.get("CheckInTime"));
                     System.out.println("Zone ID :  " + jsonObject.get("zoneId"));
                     System.out.println("Zone Name :  " + jsonObject.get("zoneName"));
                     System.out.println("Device Speed : " + jsonObject.get("deviceSpeed"));
                     System.out.println("Device Type : " + jsonObject.get("deviceType"));
                     System.out.println("Installation Ref : " + jsonObject.get("installRef")); // This is a fully randomised id and the real application id or device id is never stored in the db
                     System.out.println("---------\n");
                }
                 
            }
        } else {
            InputStream inputStream = httpResponse.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }
    }
     
     
     
    public static void getCheckInActivitiesByCheckInTimeDateRange() throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException {
         
        String bdRestUrl = bdRestBaseUrl + "?&customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey +
                "&checkInTimeStart=" + checkInTimeStart + "&checkInTimeEnd=" + checkInTimeEnd + "&pageNumber=0";
         
        CloseableHttpClient httpRestClient = HttpClients.custom().setSSLSocketFactory(getSSLContextFactory()).build();
        HttpGet request            = new HttpGet(bdRestUrl);
        HttpResponse httpResponse  = httpRestClient.execute(request);
         
        if (httpResponse.getStatusLine().getStatusCode() == 200){
            BufferedReader rd          = new BufferedReader (new InputStreamReader
                                        (httpResponse.getEntity().getContent()));
            JSONParser parser          = new JSONParser();
            String bdChecInRecords;
             
            while ( (bdChecInRecords = rd.readLine() ) != null) {
                 Object object                = parser.parse(bdChecInRecords);
                 JSONArray bdCheckInJsonArry  = (JSONArray) object;
                  
                 for (Object checkInObject : bdCheckInJsonArry) {
                      
                     JSONObject jsonObject        = (JSONObject) checkInObject;
                      
                     /*Print checkIn records returned*/             
                     System.out.println("Check-in ID : " + jsonObject.get("checkInId").toString());
                     System.out.println("Check-in Time : " +  jsonObject.get("CheckInTime"));
                     System.out.println("Zone ID :  " + jsonObject.get("zoneId"));
                     System.out.println("Zone Name :  " + jsonObject.get("zoneName"));
                     System.out.println("Device Speed : " + jsonObject.get("deviceSpeed"));
                     System.out.println("Device Type : " + jsonObject.get("deviceType"));
                     System.out.println("Installation Ref : " + jsonObject.get("installRef")); // This is a fully randomised id and the real application id or device id is never stored in the db
                     System.out.println("---------\n");
                }
                 
            }
        } else {
            InputStream inputStream = httpResponse.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }
    }
}
using System;
using System.Text;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Net;
using System.Web.Script.Serialization;
using System.IO;
using System.Security.Cryptography.X509Certificates;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * CheckInActivity client demonstrates fetching checkIn activities for a given zone using http web api and JSON.NET libraries
 * 100 CheckIn activities are returned per call, increment the pagenumber parameter to get records corresponding to the page
 * This api also accepts a date range as paramter(optional) where recordds within the start date and the end date range are returned
 */
namespace BluedotPublicApiClient.checkinactivityclient
{
    public class GetCheckinActivities
    {
        private static String bdCustomerApiKey    = "bc199c80-5441-11e4-b7bb-a0481cdc3311"; //This key is generated by Bluedot Point Access UI when your account is created
        private static String bdApplicationApiKey = "dc99ae20-9192-11e5-8721-0646bf53d23f"; //This apiKey is generated when you create an application
        private static String bdZoneId            = "24d9a245-2087-421b-9972-2af2ee0970f1"; //This is the id of the zone being updated. This can be fetched by calling GET zones API
        private static String receivedAtStart     = "2015-09-26";
        private static String receivedAtEnd       = "2015-09-30";
        private static String bdRestBaseUrl       = "https://api.bluedotinnovation.com/2/checkinactivities?";
        public void getCheckInActivitiesByReceivedAtDateRange()
        {
            String bdRestUrl = bdRestBaseUrl + "&customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey + "&receivedAtStart=" + receivedAtStart + "&receivedAtStart=" + receivedAtEnd + "&pagenumber=0";
            WebRequestHandler handler = new WebRequestHandler();
            X509Certificate2 certificate = new X509Certificate2();
            handler.ClientCertificates.Add(certificate);
            HttpClient httpRestClient = new HttpClient(handler);
            //specify to use TLS 1.2 as default connection
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            HttpResponseMessage serverResponse = httpRestClient.GetAsync(new Uri(bdRestUrl)).Result;
            if (serverResponse.IsSuccessStatusCode)
            {
                var result = serverResponse.Content.ReadAsStringAsync().Result;
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                dynamic checkInRecords          = serializer.Deserialize(result, typeof(object)); // Result is an array of json
                foreach (var checkInRecord in checkInRecords)
                {
                    Console.WriteLine("Check-in ID : {0} ", checkInRecord["checkInId"]);
                    Console.WriteLine("Check-in Time : {0} ", checkInRecord["checkInTime"]);
                    Console.WriteLine("Zone ID : {0} ", checkInRecord["zoneId"]);
                    Console.WriteLine("Zone Name : {0} ", checkInRecord["zoneName"]);
                    Console.WriteLine("Device Speed : {0} ", checkInRecord["deviceSpeed"]);
                    Console.WriteLine("Device Type : {0} ", checkInRecord["deviceType"]);
                    Console.WriteLine("Installation Ref : {0} ", checkInRecord["installRef"]); // This is a fully randomised id and the real application id or device id is never stored in the db
                    Console.WriteLine("---------\n");
                }               
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)serverResponse.StatusCode, serverResponse.Content.ReadAsStringAsync().Result);
            }
        }
        public void getAllCheckInActivitesByZone()
        {
            String bdRestUrl          = bdRestBaseUrl + "zoneId=" + bdZoneId + "&customerApiKey=" + bdCustomerApiKey + "&apiKey="+ bdApplicationApiKey +"&pagenumber=0";
            WebRequestHandler handler = new WebRequestHandler();
            X509Certificate2 certificate = new X509Certificate2();
            handler.ClientCertificates.Add(certificate);
            HttpClient httpRestClient = new HttpClient(handler);
            //specify to use TLS 1.2 as default connection
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            HttpResponseMessage serverResponse = httpRestClient.GetAsync(new Uri(bdRestUrl)).Result;
            if (serverResponse.IsSuccessStatusCode)
            {
                var result = serverResponse.Content.ReadAsStringAsync().Result;
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                dynamic checkInRecords          = serializer.Deserialize(result, typeof(object));   // Result is an array of json
                foreach (var checkInRecord in checkInRecords)
                {
                    Console.WriteLine("Check-in ID : {0} ", checkInRecord["checkInId"]);
                    Console.WriteLine("Check-in Time : {0} ", checkInRecord["checkInTime"]);
                    Console.WriteLine("Zone ID : {0} ", checkInRecord["zoneId"]);
                    Console.WriteLine("Zone Name : {0} ", checkInRecord["zoneName"]);
                    Console.WriteLine("Device Speed : {0} ", checkInRecord["deviceSpeed"]);
                    Console.WriteLine("Device Type : {0} ", checkInRecord["deviceType"]);
                    Console.WriteLine("Installation Ref : {0} ", checkInRecord["installRef"]); // This is a fully randomised id and the real application id or device id is never stored in the db
                    Console.WriteLine("---------\n");
                }                               
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)serverResponse.StatusCode, serverResponse.Content.ReadAsStringAsync().Result);
            }
        }
    }
}
Created by Bluedot DevOps on March 3, 2018

Start the discussion