GET Zones – Client examples

GET all Zones

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Get All Zones client demonstrates the listing of Zone details for a given customer's application using 'request' node module.
 * 100 Zones are returned per call, increment the page number parameter to get records corresponding to the page.
 */
var request  = require('request');
 
var  bdApplicationApiKey = 'c2c8211f-796f-4eda-b6ce-05467b5263a9'; //This apiKey is generated when you create an application
var  bdCustomerApiKey = '86577370-7b91-11e4-bcb7-a0481cdc3311'; //This key is generated by Bluedot Point Access UI when your account is created
request.get ( 'https://api.bluedotinnovation.com/1/zones?customerApiKey=' + bdCustomerApiKey + '&apiKey=' + bdApplicationApiKey + "&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);
    }
);

GET a specific Zone

/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Get Zone client demonstrates the listing of Zone details for a given customer's zoneId using 'request' node module.
 */
var request  = require('request');
var bdCustomerApiKey  = '76e1ae30-c616-11e5-a7c0-b8ca3a6b879d'; //This key is generated by Bluedot Point Access UI when your account is created
var bdApplicationApiKey = 'dee11930-ebff-11e5-8e27-bc305bf60831'; //This apiKey is generated when you create an application
var bdZoneId = '67f99448-a646-43c9-a6ae-0d823d65edbd'; //This is the id of the Zone being retrieved
request.get ( 'https://api.bluedotinnovation.com/1/zones?customerApiKey=' + bdCustomerApiKey + '&apiKey=' + bdApplicationApiKey + "&zoneId=" + bdZoneId,
    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);
    }
);

GET all Zones

package com.bluedotinnovation.zone;
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.
 * Get All Zones client demonstrates the listing of Zone details for a given customer's application using Apache HTTP client and JSON Simple libraries.
 * 100 Zones are returned per call, increment the page number parameter to get records corresponding to the page.
 */
public class GetAllZones extends BDCommon {
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException
    {
        String bdCustomerApiKey    = "462dacf0-2316-11e6-a994-bc305bf60831"; //This key is generated by Bluedot Point Access UI when your account is created
        String bdApplicationApiKey = "6c36c440-2316-11e6-bd45-b8ca3a6b879d"; //This apiKey is generated when you create an application.
        String bdRestUrl           = "https://api.bluedotinnovation.com/1/zones?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 bdZonesJson;
            while ((bdZonesJson = rd.readLine()) != null) {
                 Object object = parser.parse(bdZonesJson);
                 JSONArray bdZonesJsonArray = (JSONArray) object;
                 for (Object zoneObject : bdZonesJsonArray){
                     JSONObject jsonObject =  (JSONObject) zoneObject;
                     System.out.println("Zone name : " + jsonObject.get("zoneName"));
                     System.out.println("Zone id: " + jsonObject.get("zoneId"));
                     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);
        }
    }
}

GET a specific Zone

package com.bluedotinnovation.zone;
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.
 * Get Zone client demonstrates the listing of Zone details for a given customer's zoneId using Apache HTTP client and JSON Simple libraries.
 */
public class GetZone extends BDCommon {
    public static void main(String[] args) throws IOException, ParseException, KeyManagementException, NoSuchAlgorithmException
    {
        String bdCustomerApiKey    = "76e1ae30-c616-11e5-a7c0-b8ca3a6b879d"; //This key is generated by Bluedot Point Access UI when your account is created
        String bdApplicationApiKey = "dee11930-ebff-11e5-8e27-bc305bf60831"; //This apiKey is generated when you create an application.
        String bdZoneId            = "67f99448-a646-43c9-a6ae-0d823d65edbd"; //This is the id of the Zone being retrieved.
        String bdRestUrl           = "https://api.bluedotinnovation.com/1/zones?customerApiKey=" +bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey + "&zoneId=" + bdZoneId;
         
        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 bdZonesJson         = "";
            while ((bdZonesJson = rd.readLine()) != null) {
                JSONObject jsonZoneObject = (JSONObject) parser.parse(bdZonesJson);
                System.out.println("Zone name : " + jsonZoneObject.get("zoneName"));
                System.out.println("Zone id: " + jsonZoneObject.get("zoneId"));
            }
        } else {
            InputStream inputStream = httpResponse.getEntity().getContent();
            byte[] bytes            = readStream(inputStream);
            String resultString     = new String(bytes); //json error result
            System.out.println(resultString);
        }
    }
}

GET all Zones

using System;
using System.Linq;
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.IO;
using System.Web.Script.Serialization;
using System.Security.Cryptography.X509Certificates;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Get all Zones client demonstrates the listing of Zone details for a given customer
 */
namespace BluedotPublicApiClient.zoneclient
{
    public class GetAllZones
    {
        private static String bdApplicationApiKey   = "dee11930-ebff-11e5-8e27-bc305bf60831"; //This apiKey is generated when you create an application
        private static String bdCustomerApiKey      = "76e1ae30-c616-11e5-a7c0-b8ca3a6b879d"; //This key is generated by Bluedot Point Access UI when your account is created
        private static String bdRestUrl             = "https://api.bluedotinnovation.com/1/zones?customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey + "&pageNumber=0";
        public void getAllZonesForCustomer()
        {
            WebRequestHandler handler = new WebRequestHandler();
            X509Certificate2 certificate = new X509Certificate2();
            handler.ClientCertificates.Add(certificate);
            HttpClient httpRestClient = new HttpClient();
            //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 zoneRecords             = serializer.Deserialize(result, typeof(object)); // Result is an array of json
                foreach (var zoneRecord in zoneRecords)
                {
                    Console.WriteLine("zoneId : {0} ", zoneRecord["zoneId"]);
                    Console.WriteLine("name : {0} ", zoneRecord["zoneName"]);
                    Console.WriteLine("---------\n");
                }              
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)serverResponse.StatusCode, serverResponse.Content.ReadAsStringAsync().Result);
            }
        }
    }
}

GET a specific Zone

using System;
using System.Linq;
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.IO;
using System.Web.Script.Serialization;
using System.Security.Cryptography.X509Certificates;
/**
 * @author Bluedot Innovation
 * Copyright (c) 2016 Bluedot Innovation. All rights reserved.
 * Get Zone client demonstrates the listing of Zone details for a given customer
 */
namespace BluedotPublicApiClient.zoneclient
{
    public class GetZone
    {
        private static String bdCustomerApiKey      = "76e1ae30-c616-11e5-a7c0-b8ca3a6b879d"; //This apiKey is generated when you create an application
        private static String bdApplicationApiKey   = "dee11930-ebff-11e5-8e27-bc305bf60831"; //This key is generated by Bluedot Access UI when you register
        private static String bdZoneId              = "67f99448-a646-43c9-a6ae-0d823d65edbd"; //This is the id of the Zone being retrieved
        private static String bdRestUrl             = "https://api.bluedotinnovation.com/1/zones?customerApiKey=" + bdCustomerApiKey + "&apiKey=" + bdApplicationApiKey +
                                                            "&zoneId=" + bdZoneId;
         
        public void getZoneByZoneId()
        {
            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;
                Console.WriteLine("{0}", result);             
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)serverResponse.StatusCode, serverResponse.Content.ReadAsStringAsync().Result);
            }
        }
    }
}
Created by Bluedot DevOps on March 3, 2018

Start the discussion